Strange Error with PHP Sessioning
Posted: Sat Jun 14, 2003 5:52 pm
I am having a strange issue with php sessioning. It's pretty much the same code i have used over and over again on many different platforms and versions of php but on my most current host, it doesnt seem to function. Maybe someone here can help me clarify this problem.
Code for starting the session and registering my session vars when logging in... I pull the user info from a mysql members table and assign fields to vars. all that functions correctly.
// approved is from a db field in the members table . 0[off]/1[on]. yes it's set
if($approved==1) {
session_start();
// memid pulled from db, yes i am sure that $memid is set;)
session_register("memid");
// fname pulled from db, yes i am sure that $fname is set;)
session_register("fname");
header("Location: members.php\r\n");
} else {
header("Location: login.php\r\n");
}
this functions fine.
In members.php, i have the following to check for the session.
<?
session_start();
if(session_is_registered("memid")) {
// display members page. this functions fine.
} else {
header("Location: login.php\r\n");
// no session, plop back to login.php page. works fine.
}
?>
However... when i duplicate that chunk of code for members.php into other pages, i am plopped back to the login.php. I dont understand the problem. Certain pages using this sniplet function.. others dont. I have tried debugging via echo $HTTP_SESSION_VARS['memid'];exit(); and the faulty pages do not display the memid.
Thanks alot for reading this far. If you have any input or ideas please let me know. Thanks!
Code for starting the session and registering my session vars when logging in... I pull the user info from a mysql members table and assign fields to vars. all that functions correctly.
// approved is from a db field in the members table . 0[off]/1[on]. yes it's set
if($approved==1) {
session_start();
// memid pulled from db, yes i am sure that $memid is set;)
session_register("memid");
// fname pulled from db, yes i am sure that $fname is set;)
session_register("fname");
header("Location: members.php\r\n");
} else {
header("Location: login.php\r\n");
}
this functions fine.
In members.php, i have the following to check for the session.
<?
session_start();
if(session_is_registered("memid")) {
// display members page. this functions fine.
} else {
header("Location: login.php\r\n");
// no session, plop back to login.php page. works fine.
}
?>
However... when i duplicate that chunk of code for members.php into other pages, i am plopped back to the login.php. I dont understand the problem. Certain pages using this sniplet function.. others dont. I have tried debugging via echo $HTTP_SESSION_VARS['memid'];exit(); and the faulty pages do not display the memid.
Thanks alot for reading this far. If you have any input or ideas please let me know. Thanks!