whit3fir3 Posted February 6, 2008 Share Posted February 6, 2008 Is there a way to get the last page a user visited if you redirect them with a header('Location: '); I am trying to make it so that if a user visits a page and is not loged it, they automatically get redirected to a login page then after they login they are sent back to the page they last tried to access. The only problem is after I redirect $_SERVER['HTTP_REFERER'] comes up null. Any ideas? Thanks, whit3fir3 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 6, 2008 Share Posted February 6, 2008 Use sessions. When they enter a page store that page in a session variable, then use it to send them back there: Page 1: <?php session_start(); $_SESSION['return_to'] = $_SERVER['PHP_SELF']; ?> Login Page: <?php session_start(); // // login code // if (isset($_SESSION['return_to'])) { header('location: ' . $_SESSION['return_to']); exit(); } ?> Ken Quote Link to comment 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.