PHP script to check current position on Google

mate73

Junior Member
Joined
Jul 16, 2010
Messages
110
Reaction score
185
I recently built my own system in which I keep track of all my niche sites. Unfortunately I'm not able to find a PHP script which I can include and check all the sites position for specific keywords. I know there are software and free services but I want to collect all of this information automatically in my own system.

I've tried a bunch of different I found on Google but none of them worked. Any suggestions for where I can find a working one?
 
Why not build one?
 
Why not build one?

Unfortunately I just know the most basic stuff in PHP. Enough to build a site from scratch and access mysql but not enough to accomplish this. Since there are so many free services out there I thought there must be some free scripts floating around on a forum or blog.
 
Webmasterconsole has an article that's lists about 10 tools - both paid and free that do what you are after, take a look there.

If you get stuck, I would be willing to write one but would charge a fee.
 
You can easily build one by grabbing data with cURL and parsing the fetched data.
You can also search such related keywords, and find a similair script.
 
You can easily build one by grabbing data with cURL and parsing the fetched data.
You can also search such related keywords, and find a similair script.

Unfortunately I've tried more than 15 different versions and spent countless of hours looking for a working one.
 
Unfortunately I've tried more than 15 different versions and spent countless of hours looking for a working one.

Well, if you have no chances looking for a working one, why not save your hours and fire a freelancer to do the job for you. ;)
 
If you've already found such script, then modify it according to your needs and integrate it with your system. otherwise, hire a freelancer
 
You can easily build one by grabbing data with cURL and parsing the fetched data.
You can also search such related keywords, and find a similair script.

thats exactly what i would of done. CURL to login into google webmaster tools and grab the info you need
 
whatpageofsearchamion dot com this is very nice, its from 'iamnotagoodartist' who does some really nice scripts.

The site does any countries version of google and the first 10 pages. If you want it to do more than 10 you can just contact the developer and ask. Once you have the script/tool you can use it as much as you like.
 
something I just put together.

PHP:
<?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";
?>
 
Thanks. I'll give this a test. (On my iPod currently)
something I just put together.

PHP:
<?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";
?>
 
To be honest, you're probably better off just paying the monthly subscription for an established tracker.

The time and effort it takes to code and manage your own is daft compared to the $10 a month for someone else to do it.
 
To be honest, you're probably better off just paying the monthly subscription for an established tracker.

The time and effort it takes to code and manage your own is daft compared to the $10 a month for someone else to do it.

Agreed!!
 
Back
Top