tommyda Posted January 22, 2009 Share Posted January 22, 2009 I am trying to redirect my users to the previous page once they have logged in, from what I have read on other forums the http referrer is unreliable so I wrote this script using sessions but it wont work! Loging.php if($row['Activated'] > 0) { $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['s_name'] = $row['Name']; if(isset($_SESSION['prev_page'])){ $prev_page = $_SESSION['prev_page']; header("Location: $prev_page");} Index.php (where the session is supposed to be set) <?php session_start(); $_SESSION['prev_page'] = 'index.php'; if($_SESSION['s_logged_n'] == 'true'){ What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/142030-after-login-return-to-previous-page-help/ Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 Use $_GET e.g. http://mysite.com/login.php?previous_page=http://mysite.com/forum.php and then do Obviously needs more security etc. //login stuff if(isset($_GET['previous_page'])) { //after login header("Location:".$_GET['previous_page']); } Quote Link to comment https://forums.phpfreaks.com/topic/142030-after-login-return-to-previous-page-help/#findComment-743717 Share on other sites More sharing options...
tommyda Posted January 22, 2009 Author Share Posted January 22, 2009 Doesn't work i was hoping I could use sessions Quote Link to comment https://forums.phpfreaks.com/topic/142030-after-login-return-to-previous-page-help/#findComment-743723 Share on other sites More sharing options...
tommyda Posted January 22, 2009 Author Share Posted January 22, 2009 Could anyone please tell me why my original idea is not working? It seems like the session is not even being set in the index file because I am just getting a blank screen and no redirect. Quote Link to comment https://forums.phpfreaks.com/topic/142030-after-login-return-to-previous-page-help/#findComment-743732 Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 do you have session start at the top of both pages? Quote Link to comment https://forums.phpfreaks.com/topic/142030-after-login-return-to-previous-page-help/#findComment-743737 Share on other sites More sharing options...
tommyda Posted January 22, 2009 Author Share Posted January 22, 2009 yes Quote Link to comment https://forums.phpfreaks.com/topic/142030-after-login-return-to-previous-page-help/#findComment-743738 Share on other sites More sharing options...
DeanWhitehouse Posted January 22, 2009 Share Posted January 22, 2009 echo $prev_page, see if it correct, also make sure you have no output before the header Quote Link to comment https://forums.phpfreaks.com/topic/142030-after-login-return-to-previous-page-help/#findComment-743744 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.