samoi Posted September 26, 2009 Share Posted September 26, 2009 Hello guys! I have this example of login.php page: <? // login.php script! $SQL = mysql_query(" a query "); $row = mysql_fetch_row($SQL); if(mysql_num_rows($row)){ // login ok ... set vars and redirect to users.php page! session_start(); $_SESSION["user"] = $row[1]; $_SESSION["email"] = $row[4]; // .... etc vars! header("location: users.php"); } else{ // wrong login info } ?> user.php script as follow: <? session_start(); include('header.php'); ### this script has a session_start() function too! if(isset($_SESSION["user"])){ // welcome } else{ header("location: login.php"); } ?> BUT: when I login with correct info. it says "A session had already been started - ignoring session_start() in login.php" how to pass the session in all pages and let it work as it was set in the login page!? Quote Link to comment https://forums.phpfreaks.com/topic/175649-how-to-pass-a-session-to-another-page/ Share on other sites More sharing options...
bothwell Posted September 26, 2009 Share Posted September 26, 2009 You only need to start the session once, in your login page. The session info will pass through to all your pages itself, you shouldn't need to do anything else. Quote Link to comment https://forums.phpfreaks.com/topic/175649-how-to-pass-a-session-to-another-page/#findComment-925558 Share on other sites More sharing options...
Alex Posted September 26, 2009 Share Posted September 26, 2009 You only need to start the session once, in your login page. The session info will pass through to all your pages itself, you shouldn't need to do anything else. Wrong, session_start() must be placed on every page that you wish to access the super-global $_SESSION. Quote Link to comment https://forums.phpfreaks.com/topic/175649-how-to-pass-a-session-to-another-page/#findComment-925559 Share on other sites More sharing options...
samoi Posted September 26, 2009 Author Share Posted September 26, 2009 You only need to start the session once, in your login page. The session info will pass through to all your pages itself, you shouldn't need to do anything else. thank you for helping! But it doesn't seem to work! any help? Quote Link to comment https://forums.phpfreaks.com/topic/175649-how-to-pass-a-session-to-another-page/#findComment-925565 Share on other sites More sharing options...
Alex Posted September 26, 2009 Share Posted September 26, 2009 You shouldn't have session_start() twice. And since there's one inside of header.php which you're including this is causing your error. Quote Link to comment https://forums.phpfreaks.com/topic/175649-how-to-pass-a-session-to-another-page/#findComment-925566 Share on other sites More sharing options...
bothwell Posted September 27, 2009 Share Posted September 27, 2009 You only need to start the session once, in your login page. The session info will pass through to all your pages itself, you shouldn't need to do anything else. Wrong, session_start() must be placed on every page that you wish to access the super-global $_SESSION. Yes, this is true. I always put it in header.php so I forget about it right away Quote Link to comment https://forums.phpfreaks.com/topic/175649-how-to-pass-a-session-to-another-page/#findComment-925805 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.