Jump to content

[SOLVED] Strange session problem


AdRock

Recommended Posts

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; 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/66777-solved-strange-session-problem/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.