matthewcb Posted July 26, 2011 Share Posted July 26, 2011 I have a PHP login script that takes a u/n and p/w and checks it against a MySQL database. The first time I log in it validates, sets the session and sends me on to the index.php where I have validated that the session variable ($_SESSION["username"]) is indeed set. When I load another page it checks for the session variable and magically it's gone and I'm redirected to login. When I re-login using the exact same process, u/n and p/w it validates sends me to the index.php page and then no matter where I go, I stay logged in. Same pages different results. I am making sure that session_start is called before checking for the variables. I also just moved to an Apache web server with Ubuntu 10.4 and PHP5. I'm thinking it's a php.ini issue but I'm hoping someone knows for sure. Thanks. -matt Quote Link to comment https://forums.phpfreaks.com/topic/242862-_sessionusername-doesnt-work-on-first-attempt/ Share on other sites More sharing options...
wildteen88 Posted July 26, 2011 Share Posted July 26, 2011 What code are you using to login the user. And what code are you using check if a user is logged in? Quote Link to comment https://forums.phpfreaks.com/topic/242862-_sessionusername-doesnt-work-on-first-attempt/#findComment-1247430 Share on other sites More sharing options...
AyKay47 Posted July 26, 2011 Share Posted July 26, 2011 What code are you using to login the user. And what code are you using check if a user is logged in? Quote Link to comment https://forums.phpfreaks.com/topic/242862-_sessionusername-doesnt-work-on-first-attempt/#findComment-1247431 Share on other sites More sharing options...
WebStyles Posted July 26, 2011 Share Posted July 26, 2011 if I had to guess, without seeing your code, i'd say that the second file is missing session_start() at the top, so it does not find the session variable. Quote Link to comment https://forums.phpfreaks.com/topic/242862-_sessionusername-doesnt-work-on-first-attempt/#findComment-1247445 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.