为什么php curl无法将cookie保存在我的cookiefile中?

卡斯珀·泰曼斯

我正在尝试将cookie保存在curl cookiejar中。我简化了代码,但无法正常工作。

<?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日期: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内容类型:text / html

所以testcookie在标题中,但我的cookiefile保持为空。我做错了什么?我怎样才能使该示例正常工作?谢谢你!

杰里米·哈里斯(Jeremy Harris)

设置时CURLOPT_COOKIEJAR,您需要使用绝对路径。您可以使用以下方法轻松完成此操作:

curl_setopt ($ch, CURLOPT_COOKIEJAR, realpath($cookie_file) );

参考:不能在cURL PHP中使用cookie

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么php curl无法将cookie保存在我的cookiefile中?

来自分类Dev

为什么我的Cookie无法保存?

来自分类Dev

为什么PHP无法运行?

来自分类Dev

为什么我无法使用PHP的setcookie()设置cookie名称?

来自分类Dev

为什么我无法将UIFontDescriptor保存到变量中?

来自分类Dev

为什么我的JavaScript无法从php运行?

来自分类Dev

为什么我的JavaScript无法从php运行?

来自分类Dev

为什么PHP无法在Apache中运行?

来自分类Dev

为什么我的Rails会话和cookie无法持久保存?

来自分类Dev

为什么我的Rails会话和cookie无法持久保存?

来自分类Dev

为什么我无法从android获取php中的值?

来自分类Dev

为什么我的getTimestamp()方法在php中无法正常工作?

来自分类Dev

为什么firefox无法打开以在vim中解析我的php?

来自分类Dev

为什么PHP Curl弄乱了多维数组?

来自分类Dev

为什么Null值应该存在PHP?

来自分类Dev

为什么PHP无法推送到Firebase?

来自分类Dev

无法设置PHP接口功能-为什么?

来自分类Dev

为什么我的PHP代码返回inf?

来自分类Dev

PHP:为什么我的防洪脚本滞后了?

来自分类Dev

为什么未创建我的PHP会话?

来自分类Dev

为什么 PHP 跳过我的返回命令?

来自分类Dev

为什么在PHP中需要类型提示?

来自分类Dev

为什么在PHP中通过引用传递?

来自分类Dev

为什么在php中需要此语句

来自分类Dev

在PHP中为什么不起作用

来自分类Dev

为什么这样的东西在 php 中是无效的?

来自分类Dev

为什么我的代码(ZipOutputStream)将空文件保存在ZIP中?

来自分类Dev

为什么在php中curl调用后set-cookie的区别

来自分类Dev

为什么我的php类不保存它的属性?

Related 相关文章

热门标签

归档