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 Link to comment https://forums.phpfreaks.com/topic/89766-header-redirect-and-_serverhttp_referer-question/ 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 Link to comment https://forums.phpfreaks.com/topic/89766-header-redirect-and-_serverhttp_referer-question/#findComment-460010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.