It is a popular theory that users coming to your website from Digg and other social media websites, are usually blind to ads and therefore aren’t likely to click them.

This is one reason why many publishers prefer to display Google Adsense (or other forms of advertisement) only to users coming in via search engines.

Some people have argued that doing this won’t hurt your overall earnings and you may just be wasting ad space that could have earned something, even if the click-through rate (CTR) went way down.

However, think about it from an advertiser’s point of view. If I’m paying for ads on your website and getting only a few or no clicks in return, either there is something wrong with my ad or I need to find another website.

By that rationale, my preference as a publisher would be to have a higher CTR to attract higher-paying ads. This is the code I use to check for the referring website and hide my ads from Diggers:

<?php
# Let publish_ads be TRUE to start off with
$publish_ads = TRUE;
# Check that we have an HTTP_REFERER header
if(isset($_SERVER['HTTP_REFERER'])) {
# See if the header contains "digg.com"
if (strpos($_SERVER['HTTP_REFERER'], 'digg.com')) {
# It does, so set publish_ads to FALSE
$publish_ads = FALSE;
}
}
?>

We could use a similar approach to do the opposite. i.e. display ads only to search users (users coming in from Google searches, for example).

<?php
# Let publish_ads be FALSE to start off with
$publish_ads = FALSE;
# Check that we have an HTTP_REFERER header
if(isset($_SERVER['HTTP_REFERER'])) {
# See if the header contains "google.co"
if (strpos($_SERVER['HTTP_REFERER'], 'google.co')) {
# It does, so set publish_ads to TRUE
$publish_ads = TRUE;
}
}
?>

Now you can check for $publish_ads any place you want to display or suppress the ads: