Last active
November 17, 2022 20:31
-
-
Save anvius/0e8d876eee7a10057005 to your computer and use it in GitHub Desktop.
Adsense Banned Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// From StackOverflow | |
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' | |
); | |
$ualist = array( | |
'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:1.9.2.14) 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_RETURNTRANSFER, TRUE); | |
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_FOLLOWLOCATION, TRUE); | |
curl_setopt($ch, CURLOPT_TIMEOUT,60); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
return $data; | |
} | |
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; | |
} | |
function is_banned($url, $ad_type='text', $format='160x600') { | |
$base_url = 'http://pagead2.googlesyndication.com/pagead/ads?adtest=on&client=ca-skdhfksdhfksdjksjd&random='.rand(1000, 10000000).'&url='.urlencode($url).'&gl=default&ad_type='.$ad_type.'&format='.$format; | |
$raw = file_get_contents_curl($base_url); | |
if (strpos($raw, 'id=ads')===FALSE) { | |
return TRUE; // BANNED | |
} else { | |
$ads_part = explode('<li', cut_str($raw, '<ul', '</ul>')); | |
$advertisers = array(); | |
for($i=1; $i<=(count($ads_part)-1); $i++) { | |
$advertisers[$i-1] = array( | |
'url' => cut_str($ads_part[$i], 'adurl=', '"'), | |
'title' => htmlspecialchars_decode(cut_str($ads_part[$i], '<span>', '</span>')), | |
'desc' => htmlspecialchars_decode(strip_tags(cut_str($ads_part[$i], '<div class=adb >', '</div>'))) | |
); | |
} | |
return $advertisers; | |
} | |
} | |
$ads = is_banned($argv[1]); | |
if(!is_array($ads)) { | |
echo("$ads está baneado\n"); | |
} else { | |
echo($argv[1]." NO está baneado\n"); | |
for ($i=0; $i<=count($ads)-1; $i++) { | |
echo("\t".$ads[$i]['url']." ".$ads[$i]['title']." ".$ads[$i]['desc']."\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment