PHP curl,保存会话 [英] PHP curl, preserve session
问题描述
我正在制作一个应用程序,用于从网站中删除数据,根据需要对其进行格式化,并将其显示给用户。现在,网站不允许跨网站脚本请求,因此我使用PHP的curl来检索网页。
-
使用浏览器,当您第一次访问时,网站会为您提供一个Cookie,要求您登录,并在后续请求中提供您请求的实际页面。
-
使用PHP的curl,网站只会给我一个页面要求我登录。我认为,给我的PHP服务器一个cookie。如何保存此Cookie并在后续请求中显示?
例如:
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_COOKIEFILE,c:/cookies/cookie.txt);
curl_setopt($ ch,CURLOPT_COOKIEJAR, - );
I'm making an app that scrapes data off a site, formats it as needed, and displays it to the user. Now, the site doesn't allow cross-site script requests, so I'm using PHP's curl to retrieve the page.
With a browser, the site gives you a cookie when you first visit, asking you to log in, and on subsequent requests will give you the actual page you requested.
With PHP's curl, the site will just give me the page asking me to log in. And, I presume, give my PHP server a cookie.
How can I save this cookie and present it on subsequent requests?
解决方案use a few setopts to set the cookie.
Example:
$ch=curl_init(); curl_setopt($ch, CURLOPT_COOKIEFILE, "c:/cookies/cookie.txt"); curl_setopt($ch, CURLOPT_COOKIEJAR, "-");
这篇关于PHP curl,保存会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文