weixin_33720956 2015-07-10 01:17 采纳率: 0%
浏览 17

使用CURL登录Ajax

I am trying to login to a web page and then retrieve data from a page that is only visible to logged in members. I seem to now be able to log in using CURL, however I'm unable to retrieve the page that I want.

function login($url,$postData){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, "http://domain.com/".$jobUrl."");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;

}   


$html=login('https://www.domain.com/users/ajaxonlogin.php',
'username=myemailaddress&passwd=mypassword');

echo $html;

I am able to get the following response:

{"status":"success","goto_url":"https:\/\/www.domain.com\/dashboard\/"}

I have tried adding to the bottom of the login function:

$url = "http://www.domain.com/page-that-i-want-but-requires-log-in.php";
$results_page = curl($url);
echo $results_page;

But I only receive the page as if I was NOT logged in...

Any pointers please?

Thanks.

Bruce

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
    • ¥15 大智慧怎么编写一个选股程序
    • ¥100 python 调用 cgps 命令获取 实时位置信息
    • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
    • ¥15 C语言使用vscode编码错误
    • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
    • ¥20 ensp怎么配置让PC1和PC2通讯上
    • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
    • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
    • ¥15 请各位帮我看看是哪里出了问题