Script to check if a domain is banned from Adsense program or not

I want to create this kind of script for a long time a go, inspired by Digitalpoint Adsense sandbox tool. Since I have quite a free time now, I decided to do some little research on how to create an Adsense sandbox script. Supposedly to check whether a domain is banned from Google Adsense program or not. After a little research (trial and error), actually this kind of script is not so hard to implement (i.e. once you know the correct URL to call 😛 ).

So, here I create another PHP library that will check whether a domain (the domain name, not the user Adsense account)  is banned or not. Here’s the full library source code:

//helper function
//file_get_contents using curl
function file_get_contents_curl($url, $referer="")
    $header_list=array('Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
	'Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
	'Accept-Language: en-US,en;q=0.8');

	'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)',
	'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.23 (KHTML, like Gecko) Ubuntu/10.04 Chromium/11.0.688.0 Chrome/11.0.688.0 Safari/534.23',
	'Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20110221 Ubuntu/10.04 (lucid) Firefox/3.6.14 GTB7.1',
	'Opera/9.80 (X11; Linux i686; U; en) Presto/2.7.62 Version/11.01',
	'Midori/0.2.2 (X11; Linux i686; U; en-us) WebKit/531.2+',
	'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0',
	'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1150.1 Iron/20.0.1150.1 Safari/536.11'

	$ch = curl_init();
	//curl_setopt($ch, CURLOPT_HEADER, 0); //not requesting header
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //Set curl to return the data instead of printing it to the browser.
    if ($referer!="") curl_setopt($ch, CURLOPT_REFERER, $url);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_USERAGENT, $ualist[rand(0, count($ualist)-1)]);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header_list);
	curl_setopt($ch, CURLOPT_TIMEOUT,60);
	$data = curl_exec($ch);

	return $data;

//another helper function
function cut_str($str, $left, $right) {
    $str = substr ( stristr ( $str, $left ), strlen ( $left ) );
    $leftLen = strlen ( stristr ( $str, $right ) );
    $leftLen = $leftLen ? - ($leftLen) : strlen ( $str );
    $str = substr ( $str, 0, $leftLen );
    return $str;

//main function
function is_banned($url, $ad_type='text', $format='160x600') {
	$base_url=''.rand(1000, 10000000).'&url='.urlencode($url).'&gl=default&ad_type='.$ad_type.'&format='.$format;
	if (strpos($raw, 'id=ads')===FALSE) {
		return TRUE; //is truly banned from Adsense
	} else {
		//get advertisers
				'url'=>cut_str($ads_part[$i], 'adurl=', '"'),
				'title'=>htmlspecialchars_decode(cut_str($ads_part[$i], '', '')),
				'desc'=>htmlspecialchars_decode(strip_tags(cut_str($ads_part[$i], '
', '
'))) ); } return $advertisers; } }

It’s a very basic PHP code without regular expression with a little cURL added. I’m sure you can improve it. 😀

How to use it:


//check if banned
if (!is_array($ads)) {
    //woops the domain is BANNED
    //do something here
} else {
    //it's not banned
    //you can show possible advertisers URL
    for ($i=0; $i<=count($ads)-1; $i++) {
        //loop through $ads
        //do something, can be shown to table or something
}  //end if

The function will return an array of possible advertisers for the input URL. If the domain is banned, the function will return TRUE, if not banned, it will return an array.

Example array of advertisers result:

array(2) {
  array(3) {
    string(28) ""
    string(24) "ITT Tech - Official Site"
    string(62) "Convenient Schedules, Over 130 Locations. Browse New Programs."
  array(3) {
    string(532) ""
    string(22) "Keller Graduate School"
    string(67) "Prepare For Success w/ Keller's Accounting Master's Degree."

Fully working demo can be tested here:
check if domain is banned by adsense

Close enough to Digitalpoint Adsense Sandbox tool.. 😛

Leave a comment ?


  1. Hi thanks for sharing this. Can you please provide a few more details on how to put this on another site?

    Thanks for your time


  2. hi,

    Can you update code

    I need this code


  3. Please share its tutorial.

  4. Hi, i know this is an old entry but i got to ask you 1 question… Normally when we make too much queries to google it kind of blocks the ip for about 30-45 mins or asks for captcha to see if a user is making the query and not a bot, is there same issue with url? Does google block you

    • yes, the rules applied on all Google products. If you “asks” too many requests to one of google services within certain timeframe, you’ll get temporary block.
      One way to minimize this auto-blocking behavior is by having multiple-IP addresses in your server and proxifying your request to different IP.
      (PHP-cURL can do this)

  5. Hello
    What is the logic to work on the demo page form?
    I could not see the source code page as the post. I would be glad if you share all codes.

  6. Hi. I try to check my site and your script flashes that my site is banned. It is not true. Check own and you can see ADs on my site. Can you fix this issue? Note. Previously few directories from my site was banned. But only few directories not a full site.
    Thank you

  7. Please Share This Code php format

  8. Hello,
    How to trigger adsense code instead of manual advertiser? Please help for the same! I mean where to add ad slot id and stuff?

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>