PHP Curl登录Cookies

时间:2011-11-01 10:28:41

标签: php cookies curl

这就是我想要实现的目标: 我不能使用真实的URL,所以我会使用网站A.com和B.com

  1. 从页面A.com我显示登录表单,然后我使用CURL将值提交到域B,登录并获取cookie名称
  2. 然后我用正确的信息和cookie名称设置标题
  3. 使用PHP位置功能
  4. 将页面重定向到B.com/welcome.php

    我的问题是我总是收到错误:你的会话已经过期了。请再次登录。 如果我使用CURL登录并获取cookie,然后使用CURL显示它工作的页面。

    CURL部分工作正常,以下代码导致会话过期错误“

    header ('Host: B.com\n');
    header ('User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1\n');
    header ('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n');
    header ('Accept-Language: en-gb,en;q=0.5\n');
    header ('Accept-Encoding: gzip, deflate\n');
    header ('Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n');
    header ('Referer: http://B.com/\n');
    header ('Content-type: application/x-www-form-urlencoded\n');
    header ('location: B.com/welcome.php');
    

    我使用这些标题的原因是因为这正是我手动登录页面时从Firefox发送的内容。

    感谢您的帮助

1 个答案:

答案 0 :(得分:0)

显然,您的浏览器没有curl使用的cookie存储库,因此当页面从浏览器检查cookie信息时,它将无法找到它所期望的内容。如果您希望此登录在浏览器中工作,则需要在浏览器中设置cookie,然后才能指向欢迎页面。