Problem with recursive page and session variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shelly

    Problem with recursive page and session variable

    I set a session variable on error in the login page and then call the login
    page again. I test on that session variable but it shows as not set. I
    checked with an echo immediately after setting the error session variable so
    I am 100% positive that it is set. The recursive entry to the login page
    echos a message that the error session variable is unset.

    Any clues?

    Here is the setting code and the testing code (commented out)"
    $MM_redirectLog inFailed = "ssLogin.ph p";
    if ($loginFoundUse r) {
    ......
    ......
    } else {
    $_SESSION['MM_LoginError'] = "Login Error";
    // echo "session variable is " . $_SESSION['MM_LoginError'];
    header("Locatio n: ". $MM_redirectLog inFailed );
    }

    Here is the test to see try to get an error message echoed:
    <?php
    if (isset($_SESSIO N['MM_LoginError'])) {
    echo "Login error =" . $_SESSION['MM_LoginError'];
    unset($_SESSION['MM_LoginError']);
    } else {
    echo "_SESSION['MM_LoginError'] not set";
    }
    ?>



  • Oli Filth

    #2
    Re: Problem with recursive page and session variable

    Shelly wrote:[color=blue]
    > I set a session variable on error in the login page and then call the login
    > page again. I test on that session variable but it shows as not set. I
    > checked with an echo immediately after setting the error session variable so
    > I am 100% positive that it is set. The recursive entry to the login page
    > echos a message that the error session variable is unset.
    >
    > Any clues?
    >
    > Here is the setting code and the testing code (commented out)"[/color]
    <... SNIP CODE...>

    Did you call session_start() at any point?

    --
    Oli

    Comment

    • Shelly

      #3
      Re: Problem with recursive page and session variable


      "Oli Filth" <catch@olifilth .co.uk> wrote in message
      news:ac%je.442$ RG2.129@newsfe6-gui.ntli.net...[color=blue]
      > Shelly wrote:[color=green]
      >> I set a session variable on error in the login page and then call the
      >> login page again. I test on that session variable but it shows as not
      >> set. I checked with an echo immediately after setting the error session
      >> variable so I am 100% positive that it is set. The recursive entry to the
      >> login page echos a message that the error session variable is unset.
      >>
      >> Any clues?
      >>
      >> Here is the setting code and the testing code (commented out)"[/color]
      > <... SNIP CODE...>
      >
      > Did you call session_start() at any point?[/color]

      Yes. Anyway, the page is calling itself. In order to have set it in the
      first place I needed to have called session_start() .

      Shelly



      Comment

      • Oli Filth

        #4
        Re: Problem with recursive page and session variable

        Shelly wrote:[color=blue]
        > "Oli Filth" <catch@olifilth .co.uk> wrote in message
        > news:ac%je.442$ RG2.129@newsfe6-gui.ntli.net...
        >[color=green]
        >>Shelly wrote:
        >>[color=darkred]
        >>> I set a session variable on error in the login page and then call the
        >>>login page again. I test on that session variable but it shows as not
        >>>set. I checked with an echo immediately after setting the error session
        >>>variable so I am 100% positive that it is set. The recursive entry to the
        >>>login page echos a message that the error session variable is unset.
        >>>
        >>>Any clues?
        >>>
        >>>Here is the setting code and the testing code (commented out)"[/color]
        >>
        >><... SNIP CODE...>
        >>
        >>Did you call session_start() at any point?[/color]
        >
        >
        > Yes. Anyway, the page is calling itself.[/color]

        You aren't calling the page, you're redirecting. But regardless, what does that
        have to do with session_start() ?
        [color=blue]
        > In order to have set it in the first place I needed to have called
        > session_start() .[/color]

        Not necessarily true.


        Can you post the complete code for this page, so we're able to see what's going
        wrong, because it's not apparent from the snippets you've posted so far.

        P.S. You must use an absolute URL in a Location header. But this is unlikely to
        be the cause of your problem.

        --
        Oli

        Comment

        • Shelly

          #5
          Re: Problem with recursive page and session variable

          "Oli Filth" <catch@olifilth .co.uk> wrote in message
          news:wg0ke.1330 3$yY4.4893@news fe5-win.ntli.net...[color=blue]
          > Can you post the complete code for this page, so we're able to see what's
          > going wrong, because it's not apparent from the snippets you've posted so
          > far.[/color]

          Here it is:

          <?php require_once('C onnections/ssLogin.php'); ?>
          <?php
          // *** Validate request to login to this site.
          session_start() ;

          $loginFormActio n = $_SERVER['PHP_SELF'];
          if (isset($accessc heck)) {
          $_SESSION['PrevUrl'] = $accesscheck;
          }

          if (isset($_POST['username'])) {

          $loginUsername= $_POST['username'];
          $MM_fldUserAuth orization = "";
          $MM_redirecttoR eferrer = false;
          $MM_redirectLog inSuccess = "ssLounge.p hp";
          $MM_redirectLog inFailed = "ssLogin.ph p"; //Redirected to
          itself <=====
          // Make the connection
          mysql_select_db ($database_ssLo gin, $ssLogin);

          // Encrypt the password
          $encryptedPassw ord = md5($_POST["password"]);
          // Define the query
          $LoginRS__query =sprintf("SELEC T username, password, level, status
          FROM ssusername WHERE username='%s' AND
          password='%s'",
          get_magic_quote s_gpc() ? $loginUsername :
          addslashes($log inUsername),
          $encryptedPassw ord);
          // Do the query
          $LoginRS = mysql_query($Lo ginRS__query, $ssLogin) or die(mysql_error ());
          $loginFoundUser = mysql_num_rows( $LoginRS);
          if ($loginFoundUse r) {
          // Found this user/password
          $loginStrGroup = "";
          // Put the fetched row into an array
          $row = mysql_fetch_ass oc($LoginRS);
          $level = $row['level'];
          $_SESSION['MM_UserLevel'] = $level;

          // Check if status is paid
          if (strcmp($row['status'], "paid")) {
          // Need a payment
          $MM_redirectLog inSuccess = "ssPayment.php" ;
          } else {
          //declare two session variables and assign them
          $_SESSION['MM_Username'] = $loginUsername;
          $_SESSION['MM_UserGroup'] = $loginStrGroup;
          $MM_redirectLog inSuccess = "ssLounge.p hp";
          if (isset($_SESSIO N['PrevUrl']) && false) {
          $MM_redirectLog inSuccess = $_SESSION['PrevUrl'];
          } // End of test if paid
          } //End of successfully found the user/password
          header("Locatio n: " . $MM_redirectLog inSuccess );

          } else {
          // log in error
          $_SESSION['MM_LoginError'] = "Login Error";
          //==> this is where I checked with an echo statement that the
          $_SESSION['MM_LoginError']
          //==> had been set. It validated that it was set when incorrect info was
          put in.
          header("Locatio n: ". $MM_redirectLog inFailed );
          } //End of checking if logged in

          }
          ?>
          <?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <title>Login Page</title>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
          </head>

          <body>
          <div align="center">
          <h3>Login Page
          </h3>
          </div>
          <form ACTION="<?php echo $loginFormActio n; ?>" name="ssLoginPa ge" id="form1"
          method="POST">
          <?php
          if (isset($_SESSIO N['MM_LoginError'])) {
          echo "Login error =" . $_SESSION['MM_LoginError'];
          unset($_SESSION['MM_LoginError']);
          //==> this is what it is supposed to do. I checked with and echo statement
          by adding
          // } else {
          //==> an echo statement that the $_SESSION['MM_LoginError'] was not set
          }
          ?>
          <p>Username:
          <input name="username" type="text" id="username" />
          </p>
          <p>Password:
          <input name="password" type="password" id="password" />
          <label></label>
          </p>
          <blockquote>
          <blockquote>
          <p align="left">
          <input name="Submit" type="submit" value="Log In" />
          </p>
          </blockquote>
          </blockquote>
          <p><a href="ssLounge. php"><img src="images/return.gif" width="138"
          height="27" border="0" /></a><a href="ssLostPas sword.php"> <img
          src="images/lost.gif" width="163" height="27" border="0" /></a></p>
          </form>
          <p>&nbsp;</p>
          <p>&nbsp;</p>
          </body>
          </html>


          Comment

          • Oli Filth

            #6
            Re: Problem with recursive page and session variable

            Shelly wrote:[color=blue]
            > "Oli Filth" <catch@olifilth .co.uk> wrote in message
            > news:wg0ke.1330 3$yY4.4893@news fe5-win.ntli.net...
            >[color=green]
            >>Can you post the complete code for this page, so we're able to see what's
            >>going wrong, because it's not apparent from the snippets you've posted so
            >>far.[/color]
            >
            >
            > Here it is:[/color]
            <...SNIP CODE...>

            Hmmm, that all looks ok (I haven't actually tried to run it, but I looked over
            the code). One thing to check, do you have any whitespace after the closing ?>
            in Connections/ssLogin.php? There must be no output (including whitespace)
            before session_start() is called...

            --
            Oli

            Comment

            • Shelly

              #7
              Re: Problem with recursive page and session variable


              "Oli Filth" <catch@olifilth .co.uk> wrote in message
              news:st2ke.1347 7$V%.10473@news fe1-gui.ntli.net...[color=blue]
              > Shelly wrote:[color=green]
              >> "Oli Filth" <catch@olifilth .co.uk> wrote in message
              >> news:wg0ke.1330 3$yY4.4893@news fe5-win.ntli.net...
              >>[color=darkred]
              >>>Can you post the complete code for this page, so we're able to see what's
              >>>going wrong, because it's not apparent from the snippets you've posted so
              >>>far.[/color]
              >>
              >>
              >> Here it is:[/color]
              > <...SNIP CODE...>
              >
              > Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
              > over the code). One thing to check, do you have any whitespace after the
              > closing ?> in Connections/ssLogin.php? There must be no output (including
              > whitespace) before session_start() is called...[/color]

              There is absolutely nothing between that closing and the openning of the
              next php for session_start() except that it is on the next line.

              Shelly


              Comment

              • Shelly

                #8
                Re: Problem with recursive page and session variable


                "Oli Filth" <catch@olifilth .co.uk> wrote in message
                news:st2ke.1347 7$V%.10473@news fe1-gui.ntli.net...[color=blue]
                > Shelly wrote:[color=green]
                >> "Oli Filth" <catch@olifilth .co.uk> wrote in message
                >> news:wg0ke.1330 3$yY4.4893@news fe5-win.ntli.net...
                >>[color=darkred]
                >>>Can you post the complete code for this page, so we're able to see what's
                >>>going wrong, because it's not apparent from the snippets you've posted so
                >>>far.[/color]
                >>
                >>
                >> Here it is:[/color]
                > <...SNIP CODE...>
                >
                > Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
                > over the code). One thing to check, do you have any whitespace after the
                > closing ?> in Connections/ssLogin.php? There must be no output (including
                > whitespace) before session_start() is called...[/color]

                Just to be sure, I changed the code to have put them in the same php and had
                the session_start() be right after the semi-colon for the require. Same
                result.

                Shelly


                Comment

                • Oli Filth

                  #9
                  Re: Problem with recursive page and session variable

                  Shelly wrote:[color=blue]
                  > "Oli Filth" <catch@olifilth .co.uk> wrote in message
                  > news:st2ke.1347 7$V%.10473@news fe1-gui.ntli.net...
                  >[color=green]
                  >>Shelly wrote:
                  >>[color=darkred]
                  >>>"Oli Filth" <catch@olifilth .co.uk> wrote in message
                  >>>news:wg0ke.1 3303$yY4.4893@n ewsfe5-win.ntli.net...
                  >>>
                  >>>
                  >>>>Can you post the complete code for this page, so we're able to see what's
                  >>>>going wrong, because it's not apparent from the snippets you've posted so
                  >>>>far.
                  >>>
                  >>>
                  >>>Here it is:[/color]
                  >>
                  >><...SNIP CODE...>
                  >>
                  >>Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
                  >>over the code). One thing to check, do you have any whitespace after the
                  >>closing ?> in Connections/ssLogin.php? There must be no output (including
                  >>whitespace) before session_start() is called...[/color]
                  >
                  >
                  > There is absolutely nothing between that closing and the openning of the
                  > next php for session_start() except that it is on the next line.
                  >[/color]

                  I meant the closing ?> tag *inside* the Connections/ssLogin.php file.

                  --
                  Oli

                  Comment

                  • Shelly

                    #10
                    Re: Problem with recursive page and session variable


                    "Oli Filth" <catch@olifilth .co.uk> wrote in message
                    news:Ix2ke.1145 1$X86.858@newsf e2-gui.ntli.net...[color=blue]
                    > Shelly wrote:[color=green]
                    >> "Oli Filth" <catch@olifilth .co.uk> wrote in message
                    >> news:st2ke.1347 7$V%.10473@news fe1-gui.ntli.net...
                    >>[color=darkred]
                    >>>Shelly wrote:
                    >>>
                    >>>>"Oli Filth" <catch@olifilth .co.uk> wrote in message
                    >>>>news:wg0ke. 13303$yY4.4893@ newsfe5-win.ntli.net...
                    >>>>
                    >>>>
                    >>>>>Can you post the complete code for this page, so we're able to see
                    >>>>>what's going wrong, because it's not apparent from the snippets you've
                    >>>>>posted so far.
                    >>>>
                    >>>>
                    >>>>Here it is:
                    >>>
                    >>><...SNIP CODE...>
                    >>>
                    >>>Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
                    >>>over the code). One thing to check, do you have any whitespace after the
                    >>>closing ?> in Connections/ssLogin.php? There must be no output (including
                    >>>whitespace ) before session_start() is called...[/color]
                    >>
                    >>
                    >> There is absolutely nothing between that closing and the openning of the
                    >> next php for session_start() except that it is on the next line.
                    >>[/color]
                    >
                    > I meant the closing ?> tag *inside* the Connections/ssLogin.php file.[/color]

                    The closing tag greater-than sign is the very last character in that file.

                    Shelly


                    Comment

                    • Oli Filth

                      #11
                      Re: Problem with recursive page and session variable

                      Shelly wrote:[color=blue]
                      > "Oli Filth" <catch@olifilth .co.uk> wrote in message
                      > news:Ix2ke.1145 1$X86.858@newsf e2-gui.ntli.net...
                      >[color=green]
                      >>Shelly wrote:
                      >>[color=darkred]
                      >>>"Oli Filth" <catch@olifilth .co.uk> wrote in message
                      >>>news:st2ke.1 3477$V%.10473@n ewsfe1-gui.ntli.net...
                      >>>
                      >>>
                      >>>>Shelly wrote:
                      >>>>
                      >>>>
                      >>>>>"Oli Filth" <catch@olifilth .co.uk> wrote in message
                      >>>>>news:wg0ke .13303$yY4.4893 @newsfe5-win.ntli.net...
                      >>>>>
                      >>>>>
                      >>>>>
                      >>>>>>Can you post the complete code for this page, so we're able to see
                      >>>>>>what's going wrong, because it's not apparent from the snippets you've
                      >>>>>>posted so far.
                      >>>>>
                      >>>>>
                      >>>>>Here it is:
                      >>>>
                      >>>><...SNIP CODE...>
                      >>>>
                      >>>>Hmmm, that all looks ok (I haven't actually tried to run it, but I looked
                      >>>>over the code). One thing to check, do you have any whitespace after the
                      >>>>closing ?> in Connections/ssLogin.php? There must be no output (including
                      >>>>whitespac e) before session_start() is called...
                      >>>
                      >>>
                      >>>There is absolutely nothing between that closing and the openning of the
                      >>>next php for session_start() except that it is on the next line.
                      >>>[/color]
                      >>
                      >>I meant the closing ?> tag *inside* the Connections/ssLogin.php file.[/color]
                      >
                      >
                      > The closing tag greater-than sign is the very last character in that file.
                      >[/color]

                      Ok... the only other thing I can spot is that you need an exit() call after the
                      header() call.

                      --
                      Oli

                      Comment

                      • Shelly

                        #12
                        Re: Problem with recursive page and session variable


                        "Oli Filth" <catch@olifilth .co.uk> wrote in message
                        news:gJ2ke.1351 4$yY4.7976@news fe5-win.ntli.net...[color=blue]
                        > Shelly wrote:[color=green]
                        >> "Oli Filth" <catch@olifilth .co.uk> wrote in message
                        >> news:Ix2ke.1145 1$X86.858@newsf e2-gui.ntli.net...
                        >>[color=darkred]
                        >>>Shelly wrote:
                        >>>
                        >>>>"Oli Filth" <catch@olifilth .co.uk> wrote in message
                        >>>>news:st2ke. 13477$V%.10473@ newsfe1-gui.ntli.net...
                        >>>>
                        >>>>
                        >>>>>Shelly wrote:
                        >>>>>
                        >>>>>
                        >>>>>>"Oli Filth" <catch@olifilth .co.uk> wrote in message
                        >>>>>>news:wg0k e.13303$yY4.489 3@newsfe5-win.ntli.net...
                        >>>>>>
                        >>>>>>
                        >>>>>>
                        >>>>>>>Can you post the complete code for this page, so we're able to see
                        >>>>>>>what's going wrong, because it's not apparent from the snippets
                        >>>>>>>you've posted so far.
                        >>>>>>
                        >>>>>>
                        >>>>>>Here it is:
                        >>>>>
                        >>>>><...SNIP CODE...>
                        >>>>>
                        >>>>>Hmmm, that all looks ok (I haven't actually tried to run it, but I
                        >>>>>looked over the code). One thing to check, do you have any whitespace
                        >>>>>after the closing ?> in Connections/ssLogin.php? There must be no
                        >>>>>output (including whitespace) before session_start() is called...
                        >>>>
                        >>>>
                        >>>>There is absolutely nothing between that closing and the openning of the
                        >>>>next php for session_start() except that it is on the next line.
                        >>>>
                        >>>
                        >>>I meant the closing ?> tag *inside* the Connections/ssLogin.php file.[/color]
                        >>
                        >>
                        >> The closing tag greater-than sign is the very last character in that
                        >> file.
                        >>[/color]
                        >
                        > Ok... the only other thing I can spot is that you need an exit() call
                        > after the header() call.[/color]

                        That was it. You are a scholar and a gentlemen. My deepest thanks. It was
                        driving me crazy

                        Shelly


                        Comment

                        Working...