acctman Posted October 19, 2009 Share Posted October 19, 2009 Hi I need sample code on how to display a message based on referring url/domain. example: if user came from http://www.site1.com/link.php then the message they'd see on http://www.site.com/landing-page.php would be "Welcome Site1 Member's" and if they're coming from site2.com it would say "Site2 Member Welcome". thanks in advance Link to comment https://forums.phpfreaks.com/topic/178259-displaying-message-based-on-referral/ Share on other sites More sharing options...
Alex Posted October 19, 2009 Share Posted October 19, 2009 You'll need to use $_SERVER['HTTP_REFERER'], and preferably a regular expression to parse out the portion of the url you want. Link to comment https://forums.phpfreaks.com/topic/178259-displaying-message-based-on-referral/#findComment-939888 Share on other sites More sharing options...
acctman Posted October 19, 2009 Author Share Posted October 19, 2009 You'll need to use $_SERVER['HTTP_REFERER'], and preferably a regular expression to parse out the portion of the url you want. do you have an example of how the code would look/work Link to comment https://forums.phpfreaks.com/topic/178259-displaying-message-based-on-referral/#findComment-939891 Share on other sites More sharing options...
thebadbad Posted October 19, 2009 Share Posted October 19, 2009 The simple way: <?php if (isset($_SERVER['HTTP_REFERER'])) { $info = parse_url($_SERVER['HTTP_REFERER']); if (isset($info['host'])) { echo 'Welcome ' . htmlentities($info['host']) . ' Members.'; } else { //invalid referrer } } else { //referrer not set } ?> Link to comment https://forums.phpfreaks.com/topic/178259-displaying-message-based-on-referral/#findComment-939893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.