3 Replies Latest reply on Jan 13, 2010 10:19 AM by budeborton

    how to update the session kt_login_level?

    vooila Level 1

      I have a problem, I can not update the variable kt_login_level.
      I tried to write the following code, but the variable
      kt_login_level not updated.

       

      if (!session_id()) session_start();
      $_SESSION['kt_login_level'] = isset($_SESSION['kt_login_level']) ? $_SESSION['kt_login_level'] : '';
      $new_level = $_SESSION['kt_login_level'] + 1;
      $_SESSION["kt_login_level"] = $new_level;
      session_register("kt_login_level");

       

      echo $_SESSION["kt_login_level"];

       

      Thanks for help me

        • 1. Re: how to update the session kt_login_level?
          Günter Schenk Level 4

          Not sure what exactly generates the error you´re describing, but the following simplified example works nicely:

           

          session_start();

          $_SESSION['kt_login_level'] = '2';

          $new_level = $_SESSION['kt_login_level'] + 1;

          $_SESSION["kt_login_level"] = $new_level;

          session_register("kt_login_level");

           

          echo $_SESSION["kt_login_level"];

           

          Cheers,

          Günter

          • 2. Re: how to update the session kt_login_level?
            budeborton Level 1

            Gunter,

             

            Just a question - but why even include this line below?
            "session_register("kt_login_level");"

             

            session_register is depracated, and really doesn't do anything unless the PHP version is very, very old.

             

            The line before it is:

            "$_SESSION["kt_login_level"] = $new_level;"

             

            As far as I know - that already registers the new session level.

            • 3. Re: how to update the session kt_login_level?
              budeborton Level 1

              I think your "if" statement is incomplete, and is likely causing the code to fail.

              Gunter suggested simply to start with "session_start()" which takes the IF STATEMENT out of the loop, and will most likely work perfectly.

               

              if you need the IF STATEMENT, try this (it opens and closes the action if the condition is met).

               

              if (!session_id())  {

              session_start();

              $_SESSION['kt_login_level'] = '2';

              $new_level = $_SESSION['kt_login_level'] + 1;

              $_SESSION["kt_login_level"] = $new_level;

              }

              echo $_SESSION["kt_login_level"];

               

               

              EDIT: I used Gunters simplified code, as it will work like he said. Your code still had embedded conditions (isset), unclosed parenthesis, and more possible problems that could have caused lots of problems.