Forum Moderators: coopster

Message Too Old, No Replies

PHP script to switch off AdSense

Determines if referrer is an image SE

         

HarryM

11:06 am on Oct 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I get a lot of traffic from image searches. Typically the user just looks at the image and then exits. But this counts as a page impression with Adsense, and probably influences smart pricing.

I have devised a crude PHP script which works in a test environment. It determines the referrer page, and if it is an image search engine sets a variable which prevents the ads being displayed. If the user proceeds further into the site then ads are displayed as normal.

I'm not a PHP expert so would welcome comments before I try it live. There is also the possibility that I am reinventing the wheel. :)

The code is below.

<?php
$allowads = "yes"; // used later in the html as a test for displaying ads
$from = "";
if (isset($_SERVER['HTTP_REFERER']) ) {
$from = $_SERVER['HTTP_REFERER'];
if (stristr($from, "image") ¦¦ stristr($from, "Image")) {
$allowads = "no";
}
}
?>

HarryM

10:08 am on Oct 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have changed the if statement to:

if (stristr($from, "image") ¦¦ stristr($from, "Image") ¦¦ stristr($from, "imgres")) {

Then tried it on one site. It works OK in Google, AOL, Ask, and ALTAVISTA, but I would welcome any advice on how the code could be improved.

sastro

3:25 pm on Oct 15, 2007 (gmt 0)

10+ Year Member



if(eregi("image¦imgres",$from)){
$allowads = "no";
}

HarryM

3:41 pm on Oct 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks sastro.