Adsense Employer

Printer-friendly versionPDF version
No votes yet

Disclaimer: With change to current adsense program this script is no more compatible with adsense new managed ads. This script is a candidate for removal.

This is small php script which will allow you add adsense codes easily on multiple pages, you can remove adsense codes for all of your pages with one click! This script uses function to write adsense codes, each time you have to declare the ads height and width and it will create the code just as the code supplied from adsense. If the height or width is invalid format it also detects it and shows waning! It can also show referal ads randomly on your webpage.

 

To use this script you should have basic knowledge of php. If you don't know php or don't understand any point below. Then I'll highly recommend you to not to use this script.

STEP 1: TWEAKING PHP FILE

Tweaking this file carefully is very important so first we should tweak this php file carefully.


First form this part of code change the values of  $show[ad_unit], $show[link_unit]  and $show[referal] to enable or disable ads in your site. Set them to 1 to show ads, set 0 to hide

 

function ask($what)
    {
        $show               = Array();
        
        // Set options here. 
        // Set 1 for showing ads, 0 for hidding ads

        $show[ad_unit]    = '1';  // AD Units
        $show[link_unit]  = '1';  // Link Units
        $show[referral]   = '1';  // Referral Ads
        
        return $show[$what];
    }

This part controls showing of ad unit in webpage. From the part where AdSense codes starts, carefully change value of  google_ad_client and  google_ad_channel to your one. By default they are set to ##### you should change this to your one that can be found from your codes provided from adsense website

 

// Ad Unit ---------------------------------------------------------

function ad_unit($w, $h)
    {
        if(ask('ad_unit') == '1')
            {
                // Checks if the Ad unit format is vaild
                if  ( 
                        ($w==120 and $h==240) or
                        ($w==120 and $h==600) or
                        ($w==125 and $h==125) or
                        ($w==160 and $h==600) or
                        ($w==180 and $h==150) or
                        ($w==234 and $h==60 ) or
                        ($w==300 and $h==250) or
                        ($w==336 and $h==280) or
                        ($w==468 and $h==60 ) or
                        ($w==728 and $h==90 )
                    )
                    {
                        echo
'
<div style="background-color:#00FFFF; width:'.$w.'px; height:'.$h.'px;">
<!-- Ad Unit -->
<script type="text/javascript"><!--
 google_ad_client = "####";
 google_ad_width = '.$w.';
 google_ad_height = '.$h.';
 google_ad_format = "'.$w.'x'.$h.'_as";
 google_ad_type = "text";
 google_ad_channel ="####";
 google_color_border = "F9F9F9";
 google_color_bg = "F9F9F9";
 google_color_link = "666666";
 google_color_text = "666666";
 google_color_url = "666666";
 //--></script>
 <script type="text/javascript"
   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
 </script>
<!--/Ad Unit -->
</div>
';
                    }
                else
                    {
                        echo '<font color="#ff0000"><b>Warning!</b><br>Incorrect Ad Unit format.</font>';
                    }
            }
    } 
'

 

This part controls showing of link unit in webpage. From the part where AdSense codes starts, carefully change value of  google_ad_client and  google_ad_channel to your one. By default they are set to ##### you should change this to your one that can be found from your codes provided from AdSense website

 

// Link Unit -------------------------------------------------------

function link_unit($w, $h)
    {
        if(ask('link_unit') == '1')
            {
                // Checks if the link unit format is vaild
                if  ( 
                        ($w==120 and $h==90) or
                        ($w==160 and $h==90) or
                        ($w==180 and $h==90) or
                        ($w==200 and $h==90) or
                        ($w==468 and $h==15) or
                        ($w==728 and $h==15)
                    )
                    {
                        echo
'
<div style="background-color:#00FFFF; width:'.$w.'px; height:'.$h.'px;">
<!-- Link Unit -->
<script type="text/javascript"><!--
 google_ad_client = "####";
 google_ad_width = '.$w.';
 google_ad_height = '.$h.';
 google_ad_format = "'.$w.'x'.$h.'_0ads_al";
 google_ad_channel ="####";
 google_color_border = "F9F9F9";
 google_color_bg = "F9F9F9";
 google_color_link = "666666";
 google_color_text = "666666";
 google_color_url = "999999";
 //--></script>
 <script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
 </script>
<!--/Link Unit -->
</div>
';
                    }
                else
                    {
                        echo '<font color="#ff0000"><b>Warning!</b><br>Incorrect Link Unit format.</font>';
                    }
            }
    }


 

This part controls showing of referal ads in webpage. This selects a random value from1 to 4 to show any of four referal formats.

To edit first log in to your account in adsense and generate four codes for four referal ads of your choice. Remember you should generate referral ad codes of same width and height

From the part where AdSense codes starts, carefully change value of  google_ad_client and  google_ad_channel to your one. By default they are set to ##### you should change this to your one that can be found from your codes provided from AdSense website

Now mark out the four different values google_cpa_choice found from four different ad codes generated from AdSense website for four referral ads. Put their values in $choices array. (Default values are marked with $$$$) Set the width and height from google_ad_width and google_ad_height. By default their values are @@@ and &&&

 

// Referrals --------------------------------------------------------

// This function will randomly pick up one of four referral ads and will put them in webpage

function referral($i)
    {
        if(ask('referral') == '1')
            {
                $choices    = Array('$$$$', '$$$$', '$$$$', '$$$$');
                
                // if $n is 0 then randomly choice referral                
                if($i=='0')
                    {
                        $n          = rand(0,3);
                        $selection  = $choices[$n];
                        $s          = $n+1;
                    }
                else
                    {
                        $selection  = $choices[$i];
                        $s          = $i;
                    }
                echo '






';
            }
    }

Customizing color format
Just change the hex values respectively found from your original ad codes

STEP 2: Implementing
Include this file at the top of your php pages with this code. Don't forget to correct the url

 

<? include('adsense_employer.php'); ?>

 

Showing Ad Units

To show ad unit add this script where you need.

<? link_unit(width, height); ?>

Change width and height with your choice. But that should be a AdSense valid ad unit width and height. If it is invalid, this script will show error.

Such as, to show 120x600 Ad Unit add this script

<? ad_unit(120, 600); ?>

Showing Link Units

To show link unit add this script where you need.

 

<? link_unit(width, height); ?>

Change width and height with your choice. But that should be a AdSense valid link unit width and height. If it is invalid, this script will show error.

Such as, to show 468x15 link Unit add this script

<? link_unit(468, 15); ?>

Showing Random referral ads

To show referal 1 ads
To show random referral ads add this script

<? referral(1); ?>

Similarly 2 for showing 2, 3 for 3 and 4 for showing no 4 referal ad.

To show randomly use this code. Just use 0 instead of 1,2,3 or 4

<? referral(0); ?>

 

Checking Correctness:
To check if your ad codes output from the php file completely matches your original code or not, upload checker.php into server and open that file through browser. Save the page in your computer and open it with notepad. Now match all the codes generated by the script with your original one. If it don't match, then you should have make mistake in editing the adsense_employer.php file. Edit the file again to solve problem. If still it don't match you code. Then don't use this script.

Source Files: