Dan_Mason Posted April 17, 2009 Share Posted April 17, 2009 Hello again I need to direct a page somewhere else depending on the last page the client was on, Is there any function that can do this? This is the general idea of what i want: <?php if (PreviousPage = 'http://something'): header(Location:'http://somewhere') else (PreviousPage = 'http://something_else'): header(Location:'http://somewhere_else') endif; ?> Cheers for any help Link to comment https://forums.phpfreaks.com/topic/154472-find-previous-page-url-for-if-statement/ Share on other sites More sharing options...
jackpf Posted April 17, 2009 Share Posted April 17, 2009 $_SERVER['HTTP_REFERER']; will give you the referrer. However, note that if the client came directly to the page by typing the url in the address bar, this will not be set. Link to comment https://forums.phpfreaks.com/topic/154472-find-previous-page-url-for-if-statement/#findComment-812196 Share on other sites More sharing options...
i Posted April 17, 2009 Share Posted April 17, 2009 Quote The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted. http://www.php.net/manual/en/reserved.variables.server.php $_SERVER['HTTP_REFERER'] <?php if ($_SERVER['HTTP_REFERER'] == 'http://something') { header(Location:'http://somewhere') ; } elseif ($_SERVER['HTTP_REFERER'] == 'http://something_else') { header(Location:'http://somewhere_else') ; } ?> This has real limitations. First, it must come from a page that links to your page. If you click a link in your bookmarks you get nothing - the same with typing a url... And some servers will not pass this information on to you! Finally, you get the full URL - that includes gets and path and everything, If you want just the Domain name you will have to condition it a bit. Link to comment https://forums.phpfreaks.com/topic/154472-find-previous-page-url-for-if-statement/#findComment-812253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.