Using PHP to echo message if user came from redirected site
http-referer, php
Solution
I think there may be some problems with using the 301 redirect - what I recommend is simply redirecting to a special URL from your old website - this makes it very easy and clean.
So instead of:
http://oldurl.tld -> http://newurl.tld
You can do:
http://oldurl.tld -> http://newurl.tld/specialwelcome
Problem
I am launching a new site with a brand new URL (rebranding). When a user goes to the old URL, they will be redirected to a new URL. I would like to display a message to those users, welcoming them to the new site. This message would ONLY appear to users who have been redirected. Using PHP's `$_SERVER['HTTP_REFERER']` I believe I can accomplish this, but I have run into a roadblock. The following code works great if the user comes from Google: ``` <?php $referral = $_SERVER['HTTP_REFERER']; $referral = strtolower($referral); $referral = explode ("/", $referral); $referral = $referral[2]; if ( $referral == 'www.google.com'){ ?> <div style="font-weight:bold; position:absolute; top:200px; left:50%; width:300px; margin-left:-200px; background:white; padding:50px; color:black; text-align:center; font-size:17px"> You Came From: <?php echo $referral; ?> </div> <?php }; ?> ``` This basically stores the URL of the `HTTP_REFERER`, makes it pretty, and them echoes it ONLY IF the user came form Google. I would like to do this with the URL of the old site, but it doesnt seem to be working. I am setting up the redirects using Permanent 301 redirects in the cpanel. Will `HTTP_REFERER` work with these redirects? As is, nothing is stored in the `$referral` variable when coming from the redirected site. I would like to use the same concept as the code above, but make it with with 301 redirects. Any ideas?