curl 自定义 cookie

curl 可以自定义 cookie 信息,主要通过 CURLOPT_COOKIE 这个选项

function get_curl($url,$fields=array(),$is_post=1)
{
  $ch = curl_init();  
  $referer="http://www.xxx.com";  
  curl_setopt($ch, CURLOPT_URL, $url);
  if( !empty($fields) )
  {
    $fields = implode('&',$fields);  
    // 启用时会发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
  }

  curl_setopt($ch, CURLOPT_REFERER, $referer); // 看这里,你也可以说你从google来  
  curl_setopt($ch, CURLOPT_USERAGENT, "www.domain.com"); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  //是否返回内容
  curl_setopt($ch, CURLOPT_COOKIE, "PHPSESSID=9om827nkllhubk38v7mrd32ut2");   // cookie
  curl_setopt($ch, CURLOPT_HEADER, false);//设定是否输出页面头部内容  
  curl_setopt($ch, CURLOPT_POST, $is_post); // post,get 过去  

  $filecontent = curl_exec($ch);  
  curl_close($ch);  
  return $filecontent; 
}
相关的文章:

暂无评论

写评论