复制代码金沙js娱乐场官方网站 代码如下

// This example request includes an optional API key which you will need,// Read more about why it’s useful to have an API key.,244).’.’.rand(100,复制代码 代码如下,$referer)

// 使用示例
$rez = google_search_api(array(
‘q’ => ’21andy.com’, // 查询内容
‘key’ => ‘你申请到的API KEY’,
‘userip’ => ‘你的IP地址’,
));
header(‘Content-type: text/html; charset=utf-8;’);
echo ‘

废话不多说,上代码
复制代码 代码如下:
function curlrequest($url, $postfield,$referer=”,$cookie=”) {
 //
  $ip= rand(100, 244).’.’.rand(100, 244).’.’.rand(100,
244).’.’.rand(100, 244);
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
  curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘X-FORWARDED-FOR:’.$ip,
‘CLIENT-IP:’.$ip)); //构造IP
 curl_setopt($ch, CURLOPT_REFERER, $referer); //构造来路
  $data = curl_exec($ch); //运行curl
  curl_close($ch);
  return $data;
 }
 $url=”;
 $ref=”;
 $cookies=”;//构造你的cookies
 $postfield=array(
  ‘information_id’=>201204211839164950
 );
 $postfield = http_build_query($postfield);
 $result = curlrequest($url, $postfield,$ref,$cookies);
 echo $result;

$get_file = getImagesUrl($value,$u,$header);
saveurl($get_file,’a.jpg’);

复制代码 代码如下:
// This example request includes an optional API key which you will need
to
// remove or replace with your own key.
// Read more about why it’s useful to have an API key.
// 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.
$url = “”
. “q=Paris%20Hilton&key=INSERT-YOUR-KEY&userip=USERS-IP-ADDRESS”;

例子1

‘;
print_r($rez);
echo ”;

$referer=”;

// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results…

function getImagesUrl( $url,$userinfo,$header)
{
    $ch = curl_init();
    $timeout = 1;
    curl_setopt ($ch, CURLOPT_URL, “$url”);
    curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt ($ch, CURLOPT_REFERER, “”);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_USERAGENT, “$userinfo”);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);     
    $contents = curl_exec($ch);
    curl_close($ch);
    //echo $contents;
    return $contents ;
   
}

// 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);

浏览器访问one.php。页面打印如下:

API KEY 申请地址:

 //请求来源ip
 //[注]此处的IP打印顺序是目前很多开源系统的IP获取顺序
 echo ‘<hr>[IP]<br>’;
 echo $_SERVER[‘HTTP_CLIENT_IP’];
 echo ‘<br>’;
 echo $_SERVER[‘HTTP_X_FORWARDED_FOR’];
 echo ‘<br>’;
 echo $_SERVER[‘REMOTE_ADDR’];

由此,我们可以写个函数像这样
复制代码 代码如下:
function google_search_api($args, $referer = ”,
$endpoint = ‘web’){
$url = “;
if ( !array_key_exists(‘v’, $args) )
$args[‘v’] = ‘1.0’;
$url .= ‘?’.http_build_query($args, ”, ‘&’);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$body = curl_exec($ch);
curl_close($ch);
return json_decode($body);
}

function saveurl( $handle ,$filename)
{
    $fp =
fopen($filename,”w”);
    fwrite($fp,$handle);
    unset($fp);
    unset($handle);
}

例子2