Home > Article > Backend Development > The option to set cookies in curl is always false
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>
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>