我正在尝试在curl cookiejar中保存一个cookie.我简化了我的代码,但它不起作用.
原文链接:https://www.f2er.com/php/133652.html<?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; ?>
setcookie.PHP
<?PHP $value = 'something from somewhere'; setcookie("TestCookie",$value); ?>
收到标题
HTTP/1.1 200 OK Date: Thu,10 Oct 2013 12:10:37 GMT Server:
Apache/2.4.4 (Win64) PHP/5.4.12 X-Powered-By: PHP/5.4.12 Set-Cookie:
TestCookie=something+from+somewhere Content-Length: 0 Content-Type:
text/html
所以testcookie在标题中,但我的cookiefile保持空白.我做错了什么?我可以尝试使这个例子有效吗?谢谢!