PHP CURL返回403禁止响应

时间:2017-06-04 07:45:19

标签: php curl nginx

我有问题。前段时间代码停止工作。服务器在CURL请求上返回403 Forbidden nginx / 1.8.0响应。代码在其他域上运行良好。我无法解决这个问题。需要你的帮助。

private $referer;

private $useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) 
AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.65 Safari/525.19';

private $connect;

private $page;
private $last_open_url;

public function __construct( $with_cookies, $with_redirects, $max_timeout = 30 ) {
   $ch = curl_init();
   //curl_setopt($ch, CURLOPT_HEADER, true);
   curl_setopt($ch, CURLOPT_HEADER, 0);

   if($with_cookies) {
       curl_setopt($ch, CURLOPT_COOKIEFILE,  'cookiefile');
       curl_setopt($ch, CURLOPT_COOKIEJAR,  'cookiefile');

   }

   if ($with_redirects) {
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
   }

   curl_setopt($ch, CURLOPT_TIMEOUT, $max_timeout);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $max_timeout-1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   //curl_setopt($ch, CURLINFO_HEADER_OUT, true );
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

   curl_setopt($ch, CURLOPT_AUTOREFERER, true);
   curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);

   $this->connect = curl_copy_handle($ch);
} 

    public function go( $url, $post = false, $inc_ref = false )
{
    $ch_copy = curl_copy_handle($this->connect);

    if( $post !== false )
    {
        curl_setopt($ch_copy, CURLOPT_POST, 1);
        curl_setopt($ch_copy, CURLOPT_POSTFIELDS, $post);
    }

    if(!empty($this->referer))
        curl_setopt($ch_copy, CURLOPT_REFERER, $this->referer);

    if($inc_ref !== false)
        $this->referer = $url;

    curl_setopt($ch_copy, CURLOPT_URL, $url);

    $html = trim(curl_exec($ch_copy));
    curl_close($ch_copy);
    $this->last_open_url = $url;

    $this->page = $html;    
    return $html;
}

命令

curl -Is *domain* | head -1

还禁止从不同的服务器使用

0 个答案:

没有答案