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

The option to set cookies in curl is always false

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-25 10:37:29
Original
1085 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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template