-1

我正在尝试使用 cURL 加载 url。但是在这里我遇到了浏览器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. "
4

1 回答 1

0

我想你忘记了CURLOPT_COOKIE,试着把它设置为 TRUE

于 2013-10-17T07:30:10.657 回答