lead_zepplin Posted December 18, 2010 Share Posted December 18, 2010 I have my php pages set up like this: 1. log in with login.php 2. that sends you to main.php 3. in main.php, there are links to page-a.php, page-b.php, page-c.php, etc. when you type in a password at login.php, it passes your input to main.php. the correct password is hardcoded in main.php. if it matches, a session variable is set, which should be able to be used on page-a.php, page-b.php, page-c.php, etc. to verify that whoever accesses those pages has gone through the login process. if the session variable doesn't match (or null) the user is redirected to the login page. also the session variable is checked (recursively) when accessing main.php, just like the other pages. the problem is, it's as if each page starts over. the session variable does not make it beyond the page that sets it. it should be passed on to the next page but it's not. I used an echo statement in page-a.php to verify and rem'd out the rest of the code. no echo because session value is null, page goes on to load the html. without the code rem'd out it redirects the user to login.php. code: LOGIN.PHP <? session_start(); if(isset($_SESSION['aaa'])) unset($_SESSION['aaa']); ?> <html> <head> <title>title</title> </head> <body> <table width="400" align="center" border="0" bordercolor="#000099" bordercolordark="#000066" bordercolorlight="#6666FF"> <tr bgcolor="#B0C4DE"> <td> <form action="main.php" method="POST"> <p align="center"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#FFFFFF"><br> Password</font></strong> <input name="pwfield" type="password" value size="20" maxlength=20> <input type="submit" value="Login"></p> </form> </td></tr></table> </body></html> MAIN.PHP <? if ($_SESSION['aaa']!="abcdef") { $password="twinkies"; if ($_POST["pwfield"]==$password) $_SESSION['aaa']="abcdef"; // successful login else {header("Location: login.php"); exit();} } ?> <html> <head> <title>title</title> </head> <body> <a href="page-a.php">Page A</a> <a href="page-b.php">Page B</a> <a href="page-c.php">Page C</a> </body></html> PAGE-A.PHP <? echo $_SESSION['aaa']; //if ($_SESSION['aaa']!="abcdef") //header("Location: login.php"); //exit(); ?> <html> <head> <title>title</title> </head> <body> ... Quote Link to comment https://forums.phpfreaks.com/topic/222041-passing-session-to-the-next-page/ Share on other sites More sharing options...
denno020 Posted December 18, 2010 Share Posted December 18, 2010 have you put session_start() on every page at the very top? I doesn't show in your code that you've posted, not sure if you've omitted it as it's inferred, or if you forgot to add it. Denno Quote Link to comment https://forums.phpfreaks.com/topic/222041-passing-session-to-the-next-page/#findComment-1148922 Share on other sites More sharing options...
lead_zepplin Posted December 18, 2010 Author Share Posted December 18, 2010 that was it. I didn't think it was necessary to include on every page. tyvm Quote Link to comment https://forums.phpfreaks.com/topic/222041-passing-session-to-the-next-page/#findComment-1148938 Share on other sites More sharing options...
denno020 Posted December 18, 2010 Share Posted December 18, 2010 I must admit, it's a bit confusing. You would think that you're starting a brand new session on each page. It would be nice if there was a "continue_session()" or, "extend_session()" function, but there isn't lol. Denno Quote Link to comment https://forums.phpfreaks.com/topic/222041-passing-session-to-the-next-page/#findComment-1148940 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.