Introducing AdSensePHP
Today I introduce a set of PHP scripts I call AdSensePHP. These scripts, available in Lite (free) and Pro (commercial) versions, let you easily insert AdSense code into your website or blog pages. After configuring the script with your AdSense publisher ID and default settings, all you do is insert code like this into your pages:
<?php echo adsensephp_large_rectangle(); ?>
The generated code is identical to what you’d get from your AdSense console.
The Lite version provides basic functionality. The Pro version adds support for things like channel names, color palettes,
referral units, and other features.
Installation
For the Lite version, download adsensephp-lite.zip, unzip its contents onto your web server and include the adsensephp-lite.php file as required to access the AdSensePHP functions.
The Pro version is still under development.
Usage
All ad unit formats are supported via the following PHP functions:
- adsensephp_leaderboard()
- adsensephp_banner()
- adsensephp_half_banner()
- adsensephp_skyscraper()
- adsensephp_wide_skyscraper()
- adsensephp_vertical_banner()
- adsensephp_large_rectangle()
- adsensephp_medium_rectangle()
- adsensephp_square()
- adsensephp_small_square()
- adsensephp_small_rectangle()
- adsensephp_button()
All of these functions take a channel ID as an optional parameter. Link units are also supported via these functions:
- adsensephp_horizontal_linkunit()
- adsensephp_vertical_linkunit()
The link unit functions take a width parameter as well as optional number of ads (4 or 5) and channel parameters.
If you want more flexibility, the adsensephp_adunit() and adsensephp_linkunit() functions are also available.
For now, the only documentation is in the PHP source code. More to come, though!
Licensing
AdSensePHP Lite is free for anyone to use. You can even bundle it with WordPress themes or whatever. No link back is required, although of course any links are appreciated!
AdSensePHP Pro is a commercial product. Initially it will only be available (when it’s ready!) to purchasers of Uncommon AdSense.
Comments and suggestions are appreciated. Either leave them here on this blog or else drop me a note.
To see the script in action, just view the source of any page on this site. All the ads are generated using AdSensePHP of course!
