PHP和cURL cookie [英] PHP and cURL cookies

查看:163
本文介绍了PHP和cURL cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置一个php页面,使用cURL命中第三方服务器来登录。现在我的代码成功登录到第三方服务器,但由于cURL没有发送SESSION cookie到用户,用户必须自己登录

I am trying to setup a php page which uses cURL to hit a third party server to log them in. Right now my code does successfully log in to the third party server, but since cURL is not sending the SESSION cookies to the user, the user must login in themselves

如何获取cURL将cookie转发给客户端。
感谢

How can I get cURL to forward cookies to the client. Thanks

推荐答案

查看文档下面的cURL选项:

Check out the documentation for the following cURL options:

CURLOPT_COOKIE
CURLOPT_COOKIEFILE
CURLOPT_COOKIEJAR

EDIT

仔细阅读您的问题后,恐怕告诉您没有办法将Cookie写入客户端浏览器,除非您将客户端重定向到您的网站正在尝试授权他们。浏览器Cookie在称为同源政策的安全模型上运行。这基本上意味着域只能为其OWN域发出Cookie,并且不得为其他域发出Cookie。在您的特定情况下:

After reading your question more thoroughly, I'm afraid to tell you there is NO way to write the cookies to the client browser unless you redirect the client to the site you are attempting authorize them on. Browser cookies operate on a security model known as Same Origin Policy. This basically means that domains can only issue cookies for their OWN domains and may not issue cookies for others domains. In your particular case:

client --CONTACTS--> foo.com --cURL-LOGIN--> bar.com
bar.com --bar.com-COOKIE--> foo.com --foo.com-COOKIE--> client
client --foo.com-COOKIE--> bar.com (Will not work)

基本上,foo.com无法在客户端bar.com!

Basically, foo.com CAN NOT create cookies on the client for bar.com!

这篇关于PHP和cURL cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆