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 Quote 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. Quote 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 Quote 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 } ?> Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.