Display Ads to Search Referrals
- Posted at: 8:42 am
- Filed in: Design
With the most recent design of this site I decided to do away with a few of my google ad blocks to make the site a little nicer looking. My google ads are now only displayed to those that end up here via search engines. This is really easy to do, and kinda nice if you don’t want to bombard your common visitors with ads. Below is the simple PHP used to selectively display the ads:
< ?
if (preg_match('/^http:\/\/(\w+\.)?(google|msn|yahoo|aol)\./',$_SERVER['HTTP_REFERER']) == 1)
{
?>
< ---Insert your Adsense Code Here--->
< ?
}
?>
You can see this code in action by visiting a regular post on this site and then one from google.