The option to set cookies in curl is always false

WBOY
Release: 2016-08-25 10:37:29
Original
1006 people have browsed it

Post the code directly

<code>$ch = curl_init('http://www.baidu.com');
$a = curl_setopt($ch, CURLOPT_COOKIE, 'name=houming');
$b = curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$error = curl_error($ch);
var_dump($a,$b,$error);</code>
Copy after login
Copy after login

Return results:

<code>bool(false)
bool(true)
string(0) ""</code>
Copy after login
Copy after login

Reply content:

Post the code directly

<code>$ch = curl_init('http://www.baidu.com');
$a = curl_setopt($ch, CURLOPT_COOKIE, 'name=houming');
$b = curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$error = curl_error($ch);
var_dump($a,$b,$error);</code>
Copy after login
Copy after login

Return results:

<code>bool(false)
bool(true)
string(0) ""</code>
Copy after login
Copy after login

<code>curl_error($ch);  
</code>
Copy after login

Look at the error. When I execute your code here, it is TRUE

If the above doesn’t work, you can use the following method

<code>curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: name=houming"))</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template