adam84 Posted March 13, 2007 Share Posted March 13, 2007 I am having a problem with sessions. I have three pages, leftPage(toolbar) and rightPage(extra) and centerPage(main content). I am using ajax to load all three pages into one mainPage. All of my pages have included the session file. But when I attempt to log in the sesson login function gets called and the variables get set. But when I then reload the leftPage using ajax, it seems that the variables are not set anymore because the content is not changing. This is my session file, its just has a few variables. I just want to get it working before I add more stuff to it. <? class session{ var $userid; var $logged_in; function session(){ session_start(); } function login($userID){ $this->logged_in = true; $this->userid = $_SESSION['userid'] = $userID; } function logout(){ unset($_SESSION['userid']); $this->logged_in = false; } }; $session = new session; ?> This is the leftPage file <? include("include/session.php"); if( $session->logged_in ){ echo "Logged in, YAY!"; }else{ echo "Not logged in<BR>"; echo "<A HREF=javascript:void(0); ONCLICK=loadMenuItem(1);</A>Login</A>"; } ?> <? include("include/session.php"); $link = mysql_connect ("~~~"); mysql_select_db ("~~~"); $user = $GET['user']; $pass = $GET['pass']; $query = "SELECT * FROM user WHERE user = '$user' AND pass= '$pass'"; $r = mysql_query( $query, $link ); if( mysql_num_rows( $r ) > 0){ $session->login( $row[0] ); } echo "user not found"; ?> My ajax file is where I call the function to update the leftPage Quote Link to comment Share on other sites More sharing options...
fert Posted March 13, 2007 Share Posted March 13, 2007 you have to put session_start() at the very top of the page Quote Link to comment Share on other sites More sharing options...
emehrkay Posted March 13, 2007 Share Posted March 13, 2007 should this say <?php include("include/session.php"); $session = new session(); //this is what i added if( $session->logged_in ){ echo "Logged in, YAY!"; }else{ echo "Not logged in<BR>"; echo "<A HREF=javascript:void(0); ONCLICK=loadMenuItem(1);</A>Login</A>"; } ?> Quote Link to comment Share on other sites More sharing options...
adam84 Posted March 13, 2007 Author Share Posted March 13, 2007 would i need to do that for every put that checks if the user is logged in or just once? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted March 13, 2007 Share Posted March 13, 2007 do print_r($_SESSION); are your vars in there? if not, put the session_start(); up top Quote Link to comment 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.