Weekend Projects – Search Engine Visitor Greetings

Published on Jul 5, 2009   //  Weekend Projects

Weekend Project

This week based on some requests of customers we will adding some PHP code to our site to redirect users based on the search engine details.

This first example will allow you to display a greeting message based on the search engine. You could also use this to display ads to specific search engine users. For example Google users are said more likely to click on Google Ads because they recognize them. Where someone that comes from Digg is most likely not to click on Google Ads. Add the following code to welcome Google users…

<?php
$host = $_SERVER['HTTP_REFERER'];
if (strstr($host,”google”))
{
Print(“Welcome google user. Thank you for visiting our site.”);
}
?>

Now you can modify this script to show a custom message based on a keyword…

<?php
$host = $_SERVER['HTTP_REFERER'];
if (strstr($host,”server”))
{
Print(“Looking for a server? Look at our server offerings”);
}
?>

Lastly you could modify the script to output the keyword in your message if the user used Google like this…

<?php
$host = $_SERVER['HTTP_REFERER'];
$s1 = explode(“p=”,$host);
$s2 = explode(“&”,$s1[1]);
$keyword = str_replace(“+”,” “,$s2[0]);
if (strstr($host,”google”))
{
Print(“Looking for $keyword? You will find more $keyword information here.”);
}
?>

If you get stuck let me know in the comments.

1 Comment to “Weekend Projects – Search Engine Visitor Greetings”

  • Great tips! There’s also a handy WordPress plugin that can do things like this: Who Sees Ads.