Posted on 10 Aug, 2006 by Paul
NOTE: This is only here for historical purposes. The script has since been updated and the latest version is available from:
PHP Adsense-Referrals Script Version 2.1
My original script was very basic but I’ve now extended it further and I’m releasing version 2.
Version 2 allows place of up to 4 referrals (this is the current maximum allowed by Google - Adsense, Firefox, Picasa and Adwords) - one of each type - and will randomly select which referral to display.
The script is installed & configured as before (click here to read the previous article) and its usage is almost the same, except only:
<php g_referral(); ?>is required, even when wanting to display more than one referral. Just place the code 1-4 times throughout the page you wish to place it upon.
The code:
<php
// Copyright 2006 Paul (paul at tiglo.co.uk - www.tiglo.co.uk)
// Free to use but please keep the copyright in tact
$adsense_pub_id = "ca-test";
$adsense_referral_channel = "xxxxxxxxxxxxx";
$adsense_referral = array('firefox' => 0,
'adsense' => 0,
'adwords' => 0,
'picasa' => 0);
$using_firefox = preg_match("/firefox/i", $_SERVER['HTTP_USER_AGENT']);
function rand_referral() {
global $using_firefox;
if($using_firefox == 1) {
$referral = rand(2,4);
} else {
$referral = rand(1,4);
}
return $referral;
}
function g_referral() {
global $adsense_referral;
global $using_firefox;
$referrals = 0;
while($referrals < 1) {
if(($adsense_referral['firefox'] == 1 OR $using_firefox == 1)
AND $adsense_referral['adsense'] == 1
AND $adsense_referral['adwords'] == 1
AND $adsense_referral['picasa'] == 1) {
exit;
}
$referral = rand_referral();
if($referral == 1 AND $adsense_referral['firefox'] == 0) {
firefox_referral();
$adsense_referral['firefox'] = 1;
$referrals = $referrals + 1;
} elseif($referral == 2 AND $adsense_referral['adsense'] == 0) {
adsense_referral();
$adsense_referral['adsense'] = 1;
$referrals = $referrals + 1;
} elseif($referral == 3 AND $adsense_referral['adwords'] == 0) {
adwords_referral();
$adsense_referral['adwords'] = 1;
$referrals = $referrals + 1;
} elseif($referral == 4 AND $adsense_referral['picasa'] == 0) {
picasa_referral();
$adsense_referral['picasa'] = 1;
$referrals = $referrals + 1;
}
}
}
function firefox_referral() {
global $adsense_pub_id;
global $adsense_referral_channel;
?>
<!-- Begin Firefox referral code -->
<script type="text/javascript"><!--
google_ad_client = "<?php print($adsense_pub_id); ?>";
google_ad_width = 120;
google_ad_height = 60;
google_ad_format = "120x60_as_rimg";
google_cpa_choice = "CAAQrc6TlwIaCAiFrvJfRIvdKPm093M";
google_ad_channel = "<?php print($adsense_referral_channel); ?>";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Firefox referral code -->
<?php
}
function adsense_referral() {
global $adsense_pub_id;
global $adsense_referral_channel;
?>
<!-- Begin Adsense referral code -->
<script type="text/javascript"><!--
google_ad_client = "<?php print($adsense_pub_id); ?>";
google_ad_width = 120;
google_ad_height = 60;
google_ad_format = "120x60_as_rimg";
google_cpa_choice = "CAAQ-dOWhAIaCDhxzMnYataRKIHD93M";
google_ad_channel = "<?php print($adsense_referral_channel); ?>";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Adsense referral code -->
<?php
}
function adwords_referral() {
global $adsense_pub_id;
global $adsense_referral_channel;
?>
<!-- Begin Adwords referral code -->
<script type="text/javascript"><!--
google_ad_client = "<?php print($adsense_pub_id); ?>";
google_ad_width = 120;
google_ad_height = 60;
google_ad_format = "120x60_as_rimg";
google_cpa_choice = "CAAQ-NmkgwIaCE0IWWanjWPsKKTP6n4";
google_ad_channel = "<?php print($adsense_referral_channel); ?>";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Adwords referral code -->
<?php
}
function picasa_referral() {
global $adsense_pub_id;
global $adsense_referral_channel;
?>
<!-- Begin Picasa referral code -->
<script type="text/javascript"><!--
google_ad_client = "<?php print($adsense_pub_id); ?>";
google_ad_width = 120;
google_ad_height = 60;
google_ad_format = "120x60_as_rimg";
google_cpa_choice = "CAAQtNGIlAIaCB5Js1fhN80UKJzErYMB";
google_ad_channel = "<?php print($adsense_referral_channel); ?>";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Picasa referral code -->
<?php
}
?>
If you are having problems using the code, my email address is at the top of the script and in my website’s footer.
UPDATE: I found some bugs which caused the Firefox referral to be displayed even when someone was using Firefox. However, I’ve fixed them now and these updates can be found here.
Category: Adsense | Comments: none









Write a comment: