如何让Curl使用与PHP浏览器相同的cookie [英] How to let Curl use same cookie as the browser from PHP

查看:466
本文介绍了如何让Curl使用与PHP浏览器相同的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本代表浏览器执行HTTP请求,并输出对浏览器的响应。问题是,当我从浏览器中点击链接,它抱怨cookie变量。我假设它需要网站的浏览器cookie。

I have a PHP script that does an HTTP request on behalf of the browser and the outputs the response to the browser. Problem is when I click the links from the browser on this page it complains about cookie variables. I'm assuming it needs the browsers cookie(s) for the site.

如何拦截并转发到远程站点?

how can I intercept and forward it to the remote site?

推荐答案

您不能。

如果您收到请求,您需要解析输出和替换所有链接,以便它们通过您的服务器。

If you curl the request, you will need to parse the output, and replace all links so they go thru your server.

  www.yourdomain.com/f?=www.someotherdomain.com/realpage

这样做的唯一方法是在curl请求中使用持久性cookies。 CURL可以保留Cookie本身。将会话ID分配给cookie文件(curl),以便后续请求获得相同的Cookie。当用户点击某个链接时,您需要再次调整该请求。

The only way this would work is if you use persistent cookies in your curl request. CURL can keep cookies itself. Assign a session ID to the cookie file (in curl) so subsequent requests get the same cookies. When a user clicks a link, you will need to curl the request again.

这是一个安全问题,允许site1为site2设置cookie。想象一下,如果你可以在浏览器中设置cookie的paypal和欺骗用户认为他们已经记录int或一些其他恶意动作。

It is a security issue to allow site1 to set cookies for site2. Imagine if you could set cookies in the browser for paypal and trick the user into thinking they had logged int or some other malicious action.

这篇关于如何让Curl使用与PHP浏览器相同的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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