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 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效