[英]Using PHP and CURL to log in to a website
我在登录https://example.com/my-receipts
后尝试获取页面https://example.com/sessions
。 我已经正确登录,但没有进入/my-receipts
页面(可以看到我从结果页面登录,但是它捕获了一些异常并将我重定向到帮助页面)。
这是我正在使用的代码:
//initial request with login data
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com/sessions');
curl_setopt($ch, CURLOPT_REFERER, "https://example.com/dashboard");
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'email='.urlencode($email).'&password='.urlencode($password).'&_token=');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, '4.cookie');
curl_setopt($ch, CURLOPT_COOKIEFILE, '4.cookie');
$answer = curl_exec($ch);
if (curl_error($ch)) {
echo "[E1] ".curl_error($ch);
}
//another request preserving the session
curl_setopt($ch, CURLOPT_URL, 'https://example.com/my-receipts');
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$answer = curl_exec($ch);
if (curl_error($ch)) {
echo "[E2] ".curl_error($ch);
}
echo $answer;
我正在尝试从中获取页面的网站在nginx上使用Angular JS运行Laravel。 使用此代码登录后,我已经能够获取其他页面。 可能有某种特定的框架阻止了我吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.