Monday, 11 July 2011

Adsense from google search engine only

For wordpress, to display your adsense only for visitor who came from search engine only. put this script on your file :

- In singe.php :

<?php if (function_exists('scratch99_fromasearchengine')) { if (scratch99_fromasearchengine()) { { ?>
    <br />
    <div align="center">
    <script type="text/javascript"><!--
    google_ad_client = "pub-3235367747851602";
    /* 728x90, created 6/23/09 */
    google_ad_slot = "6373321225";
    google_ad_width = 728;
    google_ad_height = 90;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>   
    </div>
    <?php }}else { ?>
    <h1>POST</h1>
    <?php }} ?>

- Put the function :

function scratch99_fromasearchengine(){
  $ref = $_SERVER['HTTP_REFERER'];
  $SE = array('/search?', 'images.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.');
  foreach ($SE as $source) {
    if (strpos($ref,$source)!==false) return true;
  }
  return false;
}

No comments:

Post a comment

Popular Posts