Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Check if keyword has any result using Google AJAX API

This is function to check if there are any google search results on the given keyword. You only need to modify it to insert your google API key.

<?php
function check_result($keyword)
{ 
    //your google API key
    $key = "";
    
    $url = "http://ajax.googleapis.com/ajax/services/search/".
    "web?v=1.0&q=".$keyword.
    "&key=".$key."&userip=".$_SERVER['REMOTE_ADDR']; 

    // sendRequest 
    // note how referer is set manually 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_REFERER, $_SERVER['SERVER_NAME']); 
    $body = curl_exec($ch); 
    curl_close($ch); 

    // now, process the JSON string 
    $json = json_decode($body); 
    if(empty($json->responseData->results)) 
    { 
            return false; 
    } 
    else 
    { 
            return true; 
    } 

}
?>

You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus