我正在尝试在 curl cookiejar 中保存一个 cookie。我已经简化了我的代码,但它不起作用。
<?php
$cookie_file = './cookies.txt';
if (! file_exists($cookie_file) || ! is_writable($cookie_file)){
echo 'Cookie file missing or not writable.';
exit;
}//cookie_file is writable, so this is not the issue
$ch = curl_init (html_entity_decode("http://localhost/kiala_test/setcookie.php"));
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec ($ch);
echo $output;
?>
设置cookie.php
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value);
?>
接收到的报头
HTTP/1.1 200 OK 日期:2013 年 10 月 10 日星期四 12:10:37 GMT 服务器:Apache/2.4.4 (Win64) PHP/5.4.12 X-Powered-By:PHP/5.4.12 Set-Cookie:TestCookie= something+from+somewhere 内容长度:0 内容类型:文本/html
所以 testcookie 在标题中,但我的 cookiefile 保持为空。我做错了什么?我该怎么做才能使这个例子起作用?谢谢你!