使用PHP和CURL登录到网站 [英] Login to website using PHP and CURL

查看:153
本文介绍了使用PHP和CURL登录到网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试自动登入 https://www.myicomfort.com/ 来撷取资料。尝试了一些例子发布,但似乎不工作。也许我传递用户名和密码时没有使用正确的字段名称。有人可以帮助吗?仍在学习PHP。谢谢!

I'm attempting to autologin to https://www.myicomfort.com/ to retrieve data. Tried some of the examples posted but does not seem to work. Maybe I'm not using the correct field names when passing the username and password. Can someone pls help? Still learning PHP. Thanks!

$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL,"https://www.myicomfort.com/");  
curl_setopt($ch, CURLOPT_COOKIEFILE,1);  
curl_setopt($ch, CURLOPT_POST, 1);  
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  
curl_setopt($ch, CURLOPT_HEADER, true);    
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);  
curl_setopt($ch, CURLOPT_TIMEOUT, 120);  

$post_array = array(  
'ctl00$RightContent$txtUserName'=>'xxxname',  
'ctl00$RightContent$txtPwd'=>'xxxpassword',  
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array); 

$output = curl_exec($ch);

curl_close($ch);

`

推荐答案

您缺少其他字段。您可以在Chrome中按Ctrl + Shift + I检查要发送的字段,然后尝试登录。点击页面,你会看到类似这样的:

You are missing the other fields. You can check which fields are being sent by pressing Ctrl+Shift+I in Chrome, then try to login. Click on the page and you will see something like this:

__LASTFOCUS:
__EVENTTARGET:
__EVENTARGUMENT:
__VIEWSTATE:/wEPDwUKMTczNjcxMDc0Mg9kFgJmD2QWAgIDD2QWBAIDD2QWBAI...
__EVENTVALIDATION:/wEWCAKI/qyXDAKSptf/CwKJn6v3AQKdg7/fBwKNoqOVDAK...
ctl00$RightContent$hdnPwd:
ctl00$RightContent$txtUserName:asfasdfa
ctl00$RightContent$txtPwd:dfasdf
ctl00$RightContent$chkRemember:on
ctl00$RightContent$btnLogin:Log in

尝试提交这些数据。一旦你这样做,你应该能够登录。

Try to submit those data too. Once you've done this, you should be able to login.

这篇关于使用PHP和CURL登录到网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆