我正在尝试使用cURL加载网址。但在这里我遇到浏览器cookie的问题。该网页要求我启用浏览器Cookie。我的代码是这样的。
public function execute() {
// Set two default options, and merge any extra ones in
if(!isset($this->options[CURLOPT_TIMEOUT])) $this->options[CURLOPT_TIMEOUT] = 45;
if(!isset($this->options[CURLOPT_COOKIESESSION])) $this->options[CURLOPT_COOKIESESSION] = TRUE;
if(!isset($this->options[CURLOPT_COOKIEJAR])) $this->options[CURLOPT_COOKIEJAR] = 'cookie.txt';
if(!isset($this->options[CURLOPT_RETURNTRANSFER])) $this->options[CURLOPT_RETURNTRANSFER] = TRUE;
if(!isset($this->options[CURLOPT_FOLLOWLOCATION])) $this->options[CURLOPT_FOLLOWLOCATION] = TRUE;
if(!isset($this->options[CURLOPT_USERAGENT])) $this->options[CURLOPT_USERAGENT] = "Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0";
if(!isset($this->options[CURLOPT_AUTOREFERER])) $this->options[CURLOPT_AUTOREFERER] = TRUE;
if(!isset($this->options[CURLOPT_CONNECTTIMEOUT])) $this->options[CURLOPT_CONNECTTIMEOUT] = 15;
if(!isset($this->options[CURLOPT_MAXREDIRS])) $this->options[CURLOPT_MAXREDIRS] = 4;
if(!isset($this->options[CURLOPT_HEADER])) $this->options[CURLOPT_HEADER] = FALSE;
if(!isset($this->options[CURLOPT_SSL_VERIFYPEER])) $this->options[CURLOPT_SSL_VERIFYPEER] = FALSE;
if(!isset($this->options[CURLOPT_FAILONERROR])) $this->options[CURLOPT_FAILONERROR] = FALSE;
if(!isset($this->options[CURLOPT_ENCODING])) $this->options[CURLOPT_ENCODING] = '';
$this->options();
$return = curl_exec($this->session);
// Request failed
if($return === FALSE){
$this->error_code = curl_errno($this->session);
$this->error_string = curl_error($this->session);
curl_close($this->session);
$this->session = NULL;
return $return;
// Request successful
} else {
$this->info = curl_getinfo($this->session);
curl_close($this->session);
$this->session = NULL;
return $return;
}
}
但仍面临同样的问题,请帮助我。
我知道,这纯粹受到网站的限制
"Before you can move on, please activate your browser cookies. "
答案 0 :(得分:0)
我认为你忘了CURLOPT_COOKIE
,尝试将其设置为TRUE