使用 cURL 传递 cookie
我意识到这已经被报道过很多次了,但由于某种原因它仍然对我不起作用。我试图通过 cURL 将 cookie 传递到页面,但目标页面仍然无法获取它。
相关代码如下。
$cookie = "did=1";
$ch = curl_init();
$cj=tempnam("/","cookiejar");
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13')" );
curl_setopt( $ch, CURLOPT_COOKIE, $cookie );
curl_setopt( $ch, CURLOPT_ENCODING, "" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
谢谢。
I realize that this has been covered a bunch of times but for some reason it's still not working for me. I'm trying to pass a cookie to a page via cURL but the destination page still won't pick it up.
Relevant code below.
$cookie = "did=1";
$ch = curl_init();
$cj=tempnam("/","cookiejar");
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13')" );
curl_setopt( $ch, CURLOPT_COOKIE, $cookie );
curl_setopt( $ch, CURLOPT_ENCODING, "" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是如何通过curl 处理cookie 的示例,请注意,您应该具有写入权限才能执行此操作。
http://curl.phptrack.com
This is example how to work by cookies by curl,and take care about it,that you should have write permission to do it.
http://curl.phptrack.com
尝试使用类似
这里的示例方法
编辑
从获取它这里
try using something like
here's sample way to do it
EDIT
got it from here