Guest kilbad Posted January 10, 2007 Share Posted January 10, 2007 I have an authentication script which, currently, once someone logs in, will give a message stating they have been logged in successfully. However, instead, I want to have it redirect the user to the page they came from. Therefore, I wanted to know how I can "grab" the last URL of the page the user came from? If I have that, I could then redirect them back.Thank you all so much in advance!Brendan Link to comment https://forums.phpfreaks.com/topic/33631-solved-how-to-get-url-of-previous-page/ Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 enjoy[code]<?function get_referrer(){ if(!$ref=@$HTTP_REFERER) $ref=$_SERVER['HTTP_REFERER']; return $ref;}echo get_referrer();?>[/code] Link to comment https://forums.phpfreaks.com/topic/33631-solved-how-to-get-url-of-previous-page/#findComment-157555 Share on other sites More sharing options...
Guest kilbad Posted January 10, 2007 Share Posted January 10, 2007 Thanks for the quick response!I posted your script at [url=http://www.kilbad.com/DEVELOPMENT/test.php]http://www.kilbad.com/DEVELOPMENT/test.php[/url], but it is giving me some weird behavior.. not echoing the page when I come from somewhere else on kilbad.com..and ideas?Thanks again! Link to comment https://forums.phpfreaks.com/topic/33631-solved-how-to-get-url-of-previous-page/#findComment-157560 Share on other sites More sharing options...
redbullmarky Posted January 10, 2007 Share Posted January 10, 2007 works for me. the $_SERVER['HTTP_REFERER'] works via hyperlinks, so simply just going to a different address/hitting the back/forward buttom won't have the desired effect as far as i know.I tried the link you provided. I also skipped to http://www.kilbad.com/DEVELOPMENT/ and clicked on the test.php link, and all worked fine.I believe some browsers can be set up to mask the HTTP_REFERER though, so it'd be worth checking whether thats why it's not showing it for you. Link to comment https://forums.phpfreaks.com/topic/33631-solved-how-to-get-url-of-previous-page/#findComment-157567 Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 works here also... and the HTTP_REFERRER is sent along with the headers, so any/all new browsers (anything after ie4) should support it... and it will only work for links, going directly there or refreshing without cache wont work. Link to comment https://forums.phpfreaks.com/topic/33631-solved-how-to-get-url-of-previous-page/#findComment-157581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.