dsf6778 2013-09-20 06:58
浏览 41
已采纳

通过会话身份验证获取页面内容

I looked through Stack Overflow for similar questions but found only pieces of information. So my problem is this:

I want to grab the content of a page let's say : needpage.php (using file_get_contents() + stream_context_create() or using cURL() ) but the page that I need redirects me to a login page ( loginpage.php - <form action=*processlogin.php*> with user and pass).

Do I need to cURL() or file_get_contents() the processlogin.php page first to POST the username and password field, then grab the sessionID and then send another request to the needpage.php I need posting:

$opts = array(
    'http' => array(
        'method' => 'GET',
        'header' => 'Cookie: PHPSESSID=0123456789abcdef0123456789abcdef'
    )
);

What do you think is the right flow? Is it possible that cURL or file_get_contents to store the cookie and then use that cookie for another page?

  • 写回答

1条回答 默认 最新

  • douqiao2008 2013-09-20 07:13
    关注

    curl_setopt() lists all kind of useful flags. Maybe CURLOPT_COOKIESESSION would help in your case? The documentation seems to claim so unless I misread it well.

    If it doesn’t work, there is CURLOPT_COOKIEJAR, which can be used to save cookie data to a file, after curl_close() has been called.

    Then it can be loaded using CURLOPT_COOKIEFILE.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)