简体   繁体   中英

passing cookie info with curl in php

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);

如果不是您自己的聊天应用程序,那么您是否不能创建某种令牌并将其作为get参数每次传递给它并进行身份验证,而不是通过cookie进行验证?

似乎您在第一个请求中设置了CURLOPT_COOKIEJAR(写),但没有从第二个请求中的同一文件中读取CURLOPT_COOKIEFILE(读)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM