zang8027 Posted January 20, 2009 Share Posted January 20, 2009 I dont know if this is javascript or what but is there a way to make a link back to the previous page you were on? Right now, I have a page that checks to see if your logged in using php. If not, it sends you to a sign in page. That uses PHP to sign you in and redirect you to the index page. But I would like to have it redirect to the page you where just on. Any way to do this? ATM i use the php command header(Location:../index.php); to send it back to the page. Quote Link to comment https://forums.phpfreaks.com/topic/141640-last-visited-page/ Share on other sites More sharing options...
Maq Posted January 20, 2009 Share Posted January 20, 2009 With javascript you can use, document.referrer. Look it up. Quote Link to comment https://forums.phpfreaks.com/topic/141640-last-visited-page/#findComment-741412 Share on other sites More sharing options...
rhodesa Posted January 20, 2009 Share Posted January 20, 2009 You use PHP for this... When the user goes to a page that is restricted, before you redirect them to the login page, put the page in a session variable: //session_start(); //Session should already be started from the code you use to validate if they are logged in $_SESSION['last_page'] = $_SERVER['REQUEST_URI']; then do your redirect to login.php header('Location: login.php'); exit; then, after they login successfully, you can redirect them: $redirect = $_SESSION['last_page'] ? $_SESSION['last_page'] : 'index.php'; header('Location: '.$redirect'); exit; Quote Link to comment https://forums.phpfreaks.com/topic/141640-last-visited-page/#findComment-741426 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.