Home  >  Article  >  Backend Development  >  The option to set cookies in curl is always false

The option to set cookies in curl is always false

WBOY
WBOYOriginal
2016-08-25 10:37:29958browse

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>

Return results:

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

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>

Return results:

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

<code>curl_error($ch);  
</code>

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>
Statement:
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
Previous article:Questions about php.iniNext article:Questions about php.ini