En este momento estás viendo ▷ Download: Free Google SERP Checker PHP Script 2022

▷ Download: Free Google SERP Checker PHP Script 2022

Download: Free Google SERP Checker PHP Script 2022

How About Automated Google SERP Checking?

There are a lot of tools out there that claim to do SERP checking. And they do it. However, most of them are commercial tools.

How does automated SERP checking work?

Basically, you have a script that sends a query to Google emulating a user search. Then, through a process called scraping the script grabs the information that Google replies. Then the script extracts the information required.

That sounds simple,

But it’s actually not. Google doesn’t like automated scripts messing around in their search page.

Why?

Because they are recording every action real users do on the search page. They do that to improve the relevance of search results. It’s a known fact that Google will boost ranks of pages on which users tend to click more in the search results. But let’s get back to the SERP checks.

So, Google doesn’t like automated scraping. That’s why from time to time they will do checks using reCaptcha or even block access for such scripts.Many automated tools involve multiple IPs and proxies to avoid getting blocked by Google.

But there’s a safer way.

Using the Google Custom Search API, let’s see how we can create our own search engine keyword position checker PHP script.

You can take this even further. You could use the same code and store the position for each keyword and link. This way you can create your own free SERP rank tracker. This could potentially be a very powerful SEO tool similar to what you get for high paying SEO tools like Ahrefs or Semrush.

Before Using The Google SERP Checking PHP Script

The SERP Checking PHP script below works with the Google Custom Search API. In order to use the script with the API you will need follow these steps:

  1. Activate Google Custom Search API and create credentials by going here: https://console.developers.google.com
  2. Create a Google Custom Search Engine here: https://cse.google.com/cse/all
  3. You can test that your credentials and the custom search engine is working here: https://developers.google.com/apis-explorer/?hl=en_US#p/customsearch/v1/search.cse.list
1. Enable Google Custom Search API
2. Create Google Custom Search Engine (don’t forget to check the checkbox “Search the entire web” which will allow searching through all sites)
Google Search Engine

In Step 1, you will be obtain a Google API key and in Step 2 you will obtain a custom Search Engine ID. These will be required in the SERP Checker PHP Script.

Without further ado, let’s take a look at

Some PHP Settings

While deploying this PHP SERP checker script on various server configurations I ran into the following error:

failed to open stream: no suitable wrapper could be found

This happens when trying to access the data from Google APIs using the PHP function file_get_contents(). To fix the error you need to make sure that your php.ini configuration file contains the following setting:

allow_url_fopen = on

The Google SERP Checker Source Code

$GOOGLE_API_KEY = 'Insert Your Google Custom Search API Key';
$GOOGLE_CSE_CX = 'Insert Your Search Engine ID';

//the search query
$query = urlencode($_POST["query"]);
//the domain for which to show the ranking
$domain = $_POST["domain"];

//gl - google host - https://developers.google.com/custom-search/docs/xml_results_appendices#countryCodes
//hl - user language - https://developers.google.com/custom-search/docs/xml_results_appendices#interfaceLanguages
//pages - how many pages should the search extend

$pages = isset($_POST["pages"])?$_POST["pages"]:1;
$gl = isset($_POST["gl"])?$_POST["gl"]:"us";
$hl = isset($_POST["hl"])?$_POST["hl"]:"en";

$found = false;
echo "<ul>";
for ($page = 1;$page <= $pages && $found == false;$page++){
$apiurl = sprintf('https://www.googleapis.com/customsearch/v1?q=%s&cx=%s&key=%s&hl=%s&gl=%s&start=%d',$query,$GOOGLE_CSE_CX,$GOOGLE_API_KEY,$hl,$gl,($page-1)*10+1);
$json = file_get_contents($apiurl);
$obj = json_decode($json);

foreach ($obj->items as $idx=>$item) {
if (strpos($item->link, $domain) ){
$found = true;
echo "<li>";
} else{
echo "<li class='other'>";
}
echo "<span class='rank'>".($idx + ($page-1)*10 +1)."</span>";
echo "<span class='title'>".$item->htmlTitle."</span>";
echo "<span class='link'>".$item->link."<small>▼</small></span>";
echo "<span class='snippet'>".$item->htmlSnippet."</span>";
echo "</li>";

}
}
if ($found !== true){
echo "<li>";
echo "<span class='title'>".$domain." not found</span>";
echo "</li>";
}
echo "</ul>";

You can download a fully working PHP script that shows the position of a domain for a certain keyword search:

En Estrategia Creativa tenemos toda la información que necesitas sobre el mundo digital y en especial para tus emprendimiento Si quieres seguir leyendo información útil  ¡echa un vistazo a nuestros artículos!

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)

Deja una respuesta