登录不成功,页面不停刷新,请问是什么问题?

来源:2-4 用cURL登陆慕课网并下载个人空间页面

hen_nam

2018-08-05 22:43

<?php
date_default_timezone_set('PRC');

$ch = curl_init();

$postFields = 'email=邮箱&password=密码&remember=1';
$httpHeader = [
    'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
    'Content-Length: ' . strlen($postFields),
];
curl_setopt($ch, CURLOPT_URL, 'http://www.imooc.com/account/login');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookiefile');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookiefile');
curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
curl_exec($ch);

$httpHeader = [
    'Content-Type: text/xml',
];
curl_setopt($ch, CURLOPT_URL, 'http://www.imooc.com/u/3073012');
curl_setopt($ch, CURL_POST, false);
curl_setopt($ch, CURL_HTTPHEADER, $httpHeader);
$result = curl_exec($ch);

curl_close($ch);

echo $result;

https://img3.mukewang.com/5b670ce10001d8d108141316.jpg

写回答 关注

2回答

  • 慕粉3935404
    2019-10-17 22:10:29

    请问大概是怎么解决的?我也遇到这种问题,不知道怎么入手解决

  • enjie
    2018-08-24 19:14:15

    也想学习一下


PHP中的数据传输神器cURL

cURL就是这样的利器,可以帮助大家操作各种网络资源

34292 学习 · 228 问题

查看课程

相似问题