참고 : Google 웹 검색 API는 2010 년 11 월 1 일부터 공식적으로 지원 중단 될 예정입니다.> Google의 지원 중단 정책에 따라 계속 작동하지만> 요청할 수있는 하루 수는 제한됩니다 . 따라서 새 맞춤 검색 API로 전환하시기 바랍니다.
양식에 따라 및 키워드 필드가이 샘플 코드는 당신이 많은 것을 포함하도록 사용자 정의 할 수 있습니다 검색 할 수있는 단 하나의 사이트를 가정 한 것입니다 keyword
이라는 가정. 사이트 입력의 이름이 site
// The request also includes the userip parameter which provides the end
// user's IP address. Doing so will help distinguish this legitimate
// server-side traffic from traffic which doesn't come from an 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 is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, /* Enter the URL of your site here */);
$body = curl_exec($ch);
curl_close($ch);
// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results...
이라고 가정합니다.