<?php
set_time_limit(0);
$results = 0;
function getlinks($url) {
$data=open_page($url);
if (stristr($data,"did not match any documents")){
return 0;
//Nothing left to search..
}
if (stripos($data,"Google does not serve more than 1000")){
return 0;
//Reached Limit
}
if (stripos($data," we have omitted some entries")){
return 0;
//Search Complete
}
if (stripos($data,"sorry.google.com")){
return 0;
//Google Temp Banned Search Phrase
}
preg_match_all('/(href|src)\=(\"|\')[^\"\'\>]+/i',$data,$media);
unset($data);
$data=preg_replace('/(href|src)(\"|\'|\=\"|\=\')(.*)/i',"$3",$media[0]);
return $data;
}
function open_page($url,$proxy=""){
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$page = curl_exec($ch);
return $page;
}
function scan($query,$start="",$searchurl){
global $results;
$url = "http://www.google.com/search?hl=en&rls=en&q=$query&start=$start";
$urls = getlinks($url);
foreach ($urls as $read){
if (!strstr($read,"google") && !strstr($read,"youtube") && (@$read{4} == ":")){
$results++;
print $read."<br />";
flush();
ob_flush();
//use for less strict comparison
if (stristr($read,$searchurl)){
//use for strict comparison
//if ($read == $searchurl){
return $results;
}
}
}
}
function serp($keyword,$url){
$i = 0;
$pages = 100;
$pages = $pages * 10;
for ($i = 0; $i <= $pages; $i++) {
$serp = scan(urlencode($keyword),$i,$url);
if ($serp > 0){ return $serp; }
$i = $i + 9;
}
}
$kw = "blackhat seo";
$url = "http://www.blackhatworld.com/";
//note that http:// and www. is important in comparison.
print "$kw : ".serp($kw,$url)."/1000";
?>