dreamwest Posted May 18, 2009 Share Posted May 18, 2009 Im trying to send a user back to a page he was viewing before he goes to login.php page page.php > login.php After login redirect back to page.php Ive done this code but i dont know if $_SERVER['HTTP_REFERER'] is the best way to track internal pages //after successful login redirect $come_from = $_SERVER['HTTP_REFERER']; if ($come_from == "site.com/login.php"){ $redirect_url = "http://site.com/index.php"; }else{ $redirect_url = "javascript:history.go(-2)"; } redirect($redirect_url) Link to comment https://forums.phpfreaks.com/topic/158569-redirect-back-to-login/ Share on other sites More sharing options...
KevinM1 Posted May 18, 2009 Share Posted May 18, 2009 Im trying to send a user back to a page he was viewing before he goes to login.php page page.php > login.php After login redirect back to page.php Ive done this code but i dont know if $_SERVER['HTTP_REFERER'] is the best way to track internal pages //after successful login redirect $come_from = $_SERVER['HTTP_REFERER']; if ($come_from == "site.com/login.php"){ $redirect_url = "http://site.com/index.php"; }else{ $redirect_url = "javascript:history.go(-2)"; } redirect($redirect_url) The problem with HTTP_REFERER is that you're not guaranteed that it'll work 100% of the time (see: http://us3.php.net/manual/en/reserved.variables.server.php). So, you essentially have two options: 1. Use JavaScript to go back, like you have above 2. Pass some sort of value/flag that represents the originating page to the login page via a query string or hidden field, then use that to determine what page to redirect to Link to comment https://forums.phpfreaks.com/topic/158569-redirect-back-to-login/#findComment-836339 Share on other sites More sharing options...
PFMaBiSmAd Posted May 18, 2009 Share Posted May 18, 2009 3. Just make your login a content "box" that gets included/required on any page that you need a login on. It displays the login form if you are not logged in, it submits to the current page since it is just included/required on any page so there is no need to redirect all over the place, and it displays a logout link when you are logged in. Link to comment https://forums.phpfreaks.com/topic/158569-redirect-back-to-login/#findComment-836373 Share on other sites More sharing options...
dreamwest Posted May 18, 2009 Author Share Posted May 18, 2009 3. Just make your login a content "box" that gets included/required on any page that you need a login on. It displays the login form if you are not logged in, it submits to the current page since it is just included/required on any page so there is no need to redirect all over the place, and it displays a logout link when you are logged in. Thats a good idea. Thanks Link to comment https://forums.phpfreaks.com/topic/158569-redirect-back-to-login/#findComment-836816 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.