How can I search within a specific website with PHP and the Google API? -


how can search within specific website php , google api? when search keyword, want result website1.com , website2.com , website3.com. example:

<input name="search" value="keyword"> <input name="as_site" value="site1.com"> <input name="as_site" value="site2.com"> <input name="as_site" value="site3.com"> 

the result should returned these 3 websites only.

note: google web search api has been officially deprecated of november 1, 2010. >will continue work per our deprecation policy, number of requests may make >per day limited. therefore, encourage move new custom search api.

according form , assuming keyword field named keyword sample code assuming have 1 site search can customize include many. assuming site input named site

// request includes userip parameter provides end // user's ip address. doing distinguish legitimate // server-side traffic traffic doesn't come end-user. $query = $_post['keyword']; $site = $_post['site']; $url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&" . "q={$query}+site:{$site}&userip=users-ip-address"; // sendrequest // note how referer set manually $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_referer, /* enter url of site here */); $body = curl_exec($ch); curl_close($ch); // now, process json string $json = json_decode($body); // have fun results... 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -