Link to home
Start Free TrialLog in
Avatar of edmondlim
edmondlim

asked on

session does not carry out all the other pages after being set ?

I've this member.php script as a SSI.

if (session_is_registered('uid')) {
   $uid = $_SESSION["uid"];
   echo ("<tr><td valign=top class=normal><br><i>Welcome $uid</i></td></tr>");
}
else
   { require ('logon.php'); }

The logon.php is a form input of userid & password.

In the beginning of every page on my site, I call require ('auth.php') and here's the script :

<?php
     session_start();
     if(isset($logon)) {
          $sql = "SELECT * FROM profile WHERE userid = '$userid' AND password = '$password'";
          $result = mysql_query($sql);
          $num = mysql_numrows($result);
          if ($num > 0) {
               $uid = mysql_result($result,0,"userid");
                     session_register("uid");
               }
          else {
               $error_msg="Invalid User-ID/Password";
               }
          mysql_free_result($result);
     }
?>

Somehow, the session "uid" was set and able to display the message welcome $userid everytime I've logon through the form. After that, when I clicked on other pages which include the member.php as SSI, it always goes into the "require ('logon.php');" section. It seems like it does not register at all. Can anybody tell me what am I missing ?
Avatar of VGR
VGR

i suppose you've register_globals=off in your php.ini because you use $_SESSION[]

in this situation, it is not recommended to session_register() session variables, but in stead to do $_SESSION['uid']=

regards
Using predefined variables also known as superglobals such as $_SESSION are preferred since 4.2.0 (External variables are no longer registered in the global scope by default, register_globals off by default)
that's what I said :D

anyway, superglobals not being global do annoy me 8-)
ASKER CERTIFIED SOLUTION
Avatar of bobsledbob
bobsledbob

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of edmondlim

ASKER

That was missing, session_start(); in member.php SSI, thanks bobsledbob.
tsss tsss tsss you wrote "In the beginning of every page on my site [I include a session_start; in a required file]"

too easy answer 8-)