Show custom message to user from google or any other site

Welcome your users with a custom message when they come from a special site. This way, you’ll have a more interactive & personal site. Surely your user will like it & you can make your site more user friendly like give you a digg when they came from Digg.com or display some related links of your site , if they come from Google.

// Get the server HTTP Referer
$referral = $_SERVER[‘HTTP_REFERER’];

// All to lowercase
$referral = strtolower($referral);

// Only get the referral website
preg_match(“/^(http:\/\/)?([^\/]+)/i”, $referral, $result);
$referral = $result[2];

// Remove subdomain from the Referer
$referral = explode (“.”, $referral);
$i = count($referral);
$referral = $referral[$i-2] . “.” . $referral[$i-1];

// Remove www. from the Referer
if (substr ($referral, 0, 4) == “www.”)
{
$referral = substr (“$referral”, 4);
}

if ($referral == “google.com”)
{
echo “Hey! You just came from google by searching $_GET[‘q’].”;
}

If you like the post & want to get more then Subscribe our blog posts. Subscribe SunwareTech.net RSS Feed Facebook Twitter Email

Both comments and pings are currently closed.

One Response to “Show custom message to user from google or any other site”

  1. Ricardo says:

    Serious addict from this page, a considerable number of your blogposts have definitely helped me out. Awaiting upgrades!

Copyright © Sunware Technologies - Your web partner