Google Search

Custom Search

Tuesday, June 24, 2008

Installation:

There are two versions of the script, depending on whether you are more willing to accept false positives or false negatives. This is necessary due to the way different browsers report their language.
1. You will need to create two text files in the home directory of your server, usads.txt and otherads.txt . Paste in ad code you want to show to US visitors(ex. YPN) in usads.txt and paste in ad code you want to show international visitors(ex. AdSense) in otherads.txt .
2. Paste one of the following script versions to the place in your template where you want to insert ads. For US visitors the Safari and Opera browsers report their language only as “en”, while Firefox and Internet Explorer report it as “en-us”. The More Restrictive version of the script will only show US ads to browsers reporting “en-us”- thus, Safari and Opera visitors will only be shown International ads, regardless of location. However, you can be sure that no ads intended for US visitors are shown to international visitors. The Less Restrictive version shows US ads to any browser reporting “en”, so American users of all browsers will be shown ads intended for Americans- but so will anyone else in an English-speaking country, primarily Great Britain and Canada. Wordpress won’t let me put php code into posts, so you will need to put < ?php (without the space) at the beginning of the script and ?> (without the space) at the end.

More Restrictive:

$language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];if (substr($language,0,5)==”en-us”){include “usads.txt”;}else {include “otherads.txt”;}
Less Restrictive:
$language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];if (substr($language,0,2)==”en”){include “usads.txt”;}else {include “otherads.txt”;}
If you are using the WP-Cache plugin, you will need to mark the code as executable by enclosing it in –mfunc tags: put < !–mfunc–>(without the space) at the beginning and < !–/mfunc–>(without the space) at the end.
Because the ad code is included in a separate text file, and seamlessly written into the page upon execution, you are not modifying the actual ad code, and are thus fully compliant with their TOS.
Thanks to Neomeme for providing this excellent script.

No comments: