drnmslpz42661 2011-04-08 00:50
浏览 42
已采纳

在php中传递curl的cookie信息

Hello and thank you for helping me with my project. So I have successfully created a script to log into my my chat, but when I try to execute the second part of the curl it says I need to log in to post a message. The first curl works by it self and logs in. So how can I stay logged in with the first curl and then move to the second part to post a message?

/* =================================================================== 
login set cookie
====================================================================== */
$clogin = curl_init();
curl_setopt ($clogin, CURLOPT_URL, $Login_URL);
curl_setopt ($clogin, CURLOPT_REFERER, $Referer);
curl_setopt ($clogin, CURLOPT_USERAGENT, $Agent);
curl_setopt ($clogin, CURLOPT_COOKIEJAR, $Cookie_Location);
curl_setopt ($clogin, CURLOPT_COOKIEFILE, $Cookie_File); 
curl_setopt ($clogin, CURLOPT_POST, 1);
curl_setopt ($clogin, CURLOPT_POSTFIELDS, $Login_Data);
curl_setopt ($clogin, CURLOPT_RETURNTRANSFER, 1);
curl_exec   ($clogin);

/* =================================================================== 
post message
====================================================================== */

$cpost = curl_init();
curl_setopt ($cpost, CURLOPT_URL, $Posting_URL);
curl_setopt ($cpost, CURLOPT_REFERER, $Login_URL);
curl_setopt ($cpost, CURLOPT_USERAGENT, $Agent);
curl_setopt ($cpost, CURLOPT_COOKIEJAR, $Cookie_Location);
curl_setopt ($cpost, CURLOPT_COOKIEFILE, $Cookie_File); 
curl_setopt ($cpost, CURLOPT_POST, 1);
curl_setopt ($cpost, CURLOPT_POSTFIELDS, $Posting_Data);
curl_setopt ($cpost, CURLOPT_RETURNTRANSFER, 1);
curl_exec   ($cpost);
curl_close($cpost);
  • 写回答

2条回答 默认 最新

  • 普通网友 2011-04-08 01:58
    关注

    It would appear you're setting CURLOPT_COOKIEJAR (write) in your first request, but not reading from the same file in your second request CURLOPT_COOKIEFILE (read)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答