Google Ranking Checker Class in PHP

Important notice: Check google rankings become a very complicated task today. So many environment variables are important so that this simple ranking checker class don’t work any more. But there are some commercial tools that can still track your rankings like sistrix or seolytics.

The only goal for an SEO is a good or very good google ranking. To ensure this you have to monitor your rankings and compare it to the positions of your competitors. With the Google AJAX Search API and my little PHP Class you can easy build a Google Ranking Checker …

The class needs an Google API key for the AJAX Search API (get it here) … it’s just one field and a click and you can start. You can check multiple keywords for multiple domains or urls, just pass this two arrays to the check() method.

Here the complete source code of the Ranking Checker, you can test it here.

googleApiKey = $googleApiKey;
		$this->checkPageCount = $checkPageCount;
	 * get rankings
	 * @example $checker->check(array('bohuco'), array(''));
	 * @param array $keywords search these keywords
	 * @param array $domains domains to compare against
	public function check($keywords, $domains) {
		$rankings = array();
		if (! is_array($keywords)) { throw new Exception('Keywords array is no array'); }
		if (! is_array($domains)) { throw new Exception('Domains array is no array'); }
		foreach($keywords as $keyword) {
			$keyword = trim($keyword);
			$rows = array();
			if ($keyword) {
			    for($i=0;$i<$this->checkPageCount;$i++) {
		    		$start = $i*8;
		    		$url = sprintf('%s&hl=de&gl=AT&q=%s&rsz=8&key=%s&start=%s', $this->googleBaseUrl, urlencode($keyword), $this->googleApiKey, $start);
		    	    if ($result = file_get_contents($url)) {
		    			$result = json_decode($result);
		    			$rows = array_merge($rows, $result->responseData->results);
		    	foreach($domains as $url) {
		    		$rankings[$keyword][$url] = '-';
		    		foreach($rows as $position => $row) {
		    			if (strpos($row->url, trim($url)) !== false) {
		    				$rankings[$keyword][$url] = $position+1;
		return $rankings;
  • Pingback: Tweets that mention Google Ranking Checker Class in PHP | bo! hu? co. --

  • Bill

    This is nice article learned new things from this site.thanks for sharing

  • Pingback: 網站製作學習誌 » [Web] 連結分享()

  • Indiana web design

    How do you post this when designing a website? Do you have the Html file?

  • GXKevin

    Nice post! ;-)

    Flying Tech

  • Pingback: Daily Digest for July 24th()

  • Soren Beck Jensen

    The demo does not work?

  • DerFichtl

    thanks for info, bug fixed, now it works again …

  • Travis L

    Demo still doesn’t seem to work.

  • DerFichtl

    @Travis Demo works! What do you want to check?

  • Ash


    This is very useful. Have you licensed this as GPL or MIT etc. Meaning may I use this in my own projects, for clients etc

    • DerFichtl

      hi, thanks for concern, the class has no license it is just free to use and modify for everyone. maybe when i have time i choose a gpl or lgpl license for it …

  • JC


    can you show us how we can invoke this script in html?

  • CJA

    I checked out the test script and its not working. I tried a few keywords and came up with no results then i tried the most obvious keyword ‘Google’ and its coming up as 9th position? it should be #1 position.

    • DerFichtl

      Thanks for comment, i have checked the code and it works fine … but: my class is using the german language version and austria as country so is on first position.

      you can easily change that in the class … and maybe i will add this feature to the online demo … when i have time …

  • CJA

    you’re absolutely right… i was thinking about that on my way home from work. If the server the script is located on is somewhere else the results will be different. i’ll have to play with your script.

    thanks for the quick feedback :)

  • Ruben Sedano

    but its not very accuracy because i prove with keyword ‘deportes’ and domain ‘’ and not results!!! (-) :S

  • Wes

    Hey DerFichtl,
    The new version works great! I see a call to RankingChecker.php. Do you have a link to the code in that file somewhere?

    I tried copying the code above to create a RankingChecker.php file to use with the new version, however I get this error:

    Fatal error: Call to undefined method RankingChecker::setLocale() in /home/wadmin/public_html/index.php on line 17

    Thank you, I really appreciate it.

    • DerFichtl

      Dear Wes!
      Thanks for using the ranking checker, you can download the new version here.

  • Pingback: New Google Ranking Checker with Locale-Support | BOHUCO()

  • Dreis

    Tnx for this! Awsome & handy script! if you had a donate button I would donate.

  • DerFichtl

    Thanks, DerFichtl!

  • buy generic Keflex

    The Zune concentrates on being a Portable Media Player. Not a web browser. Not a game machine. Maybe in the future it’ll do even better in those areas, but for now it’s a fantastic way to organize and listen to your music and videos, and is without peer in that regard. The iPod’s strengths are its web browsing and apps. If those sound more compelling, perhaps it is your best choice.

  • Pingback: reusal()

  • Pingback: keyword statistics()

  • Pingback: Best Automatic SEO tool()

  • Pingback: Fastest Automatic Backlinker()

  • Waiver Form

    Great Post

  • Waiver Form

    Great Post

  • Excelanto

    Thanks for your valuable posting.I have collect more than information from your website. It is really wonderful blog. please added more than tips. i’m working in Erp Software in india.Here providing very low price and Quality ERP,Cloud ERP, CMS , responsive webdesign and ERP. you have any more than information kindly make me call this number 044-42127512 or send your mail