AdRock Posted August 26, 2007 Share Posted August 26, 2007 I have got a strange problem with my sessions. I am able to login to my site and I can display the session values but one of my pages tells me I need to login even though I am. I have checked by echoing the sessions values and they are set so i don't know why it thinks I'm not logged in. Here is part of the code of the page that's giving me grief. <? session_register("session"); if(!isset($session['userid'])){ echo "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>"; //These variables echo fine echo $_SESSION['userid']; echo $_SESSION['username']; exit; } //the rest of it goes here if login successful I don't know if it's relevant but this is where the login page registers the session variables while($row = mysql_fetch_array($sql)) { foreach( $row AS $key => $val ) { $$key = stripslashes( $val ); } // Register some session variables! session_register('userid'); $_SESSION['userid'] = $userid; session_register('firstname'); $_SESSION['firstname'] = $first_name; session_register('last_name'); $_SESSION['lastname'] = $last_name; session_register('email_address'); $_SESSION['email_address'] = $email_address; session_register('username'); $_SESSION['username'] = $username; session_register('special_user'); $_SESSION['user_level'] = $user_level; Quote Link to comment https://forums.phpfreaks.com/topic/66777-solved-strange-session-problem/ Share on other sites More sharing options...
Ken2k7 Posted August 26, 2007 Share Posted August 26, 2007 if(!isset($session['userid'])) $_SESSION['userid'] Quote Link to comment https://forums.phpfreaks.com/topic/66777-solved-strange-session-problem/#findComment-334613 Share on other sites More sharing options...
wildteen88 Posted August 26, 2007 Share Posted August 26, 2007 YOu can drop all the session_register calls. The session_register function has been depreciated. You can just use $_SESSION['my_sess_var'] = 'value' instead. To create/edit a session variable. Also in order set/call session variables you must use $_SESSION. Using $_session, $_Session or $session is not the same. Quote Link to comment https://forums.phpfreaks.com/topic/66777-solved-strange-session-problem/#findComment-334659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.