简体   繁体   中英

Login to website using PHP and CURL

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);

`

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.

Make sure you are using all the input fields required, doing a net sniff on information being transmitted from the form results in this

'__EVENTARGUMENT'   
'__EVENTTARGET' 
'__EVENTVALIDATION'             /wEWCAKI/qyXDAKSptf/CwKJng .. etc
'__LASTFOCUS'   
'__VIEWSTATE'                   /wEPDwUKMTczNjcxMDc0Mg9kFgJmD2QWAg .. etc
'ctl00$RightContent$btnLog...'  Log in
'ctl00$RightContent$chkRem...'  on
'ctl00$RightContent$hdnPwd' 
'ctl00$RightContent$txtPwd'     vyvuy
'ctl00$RightContent$txtUse...'  iuhgiu

See also this question on SO where I believe they suggested to at a missing login button

U can look into the source code of that page, there are many hidden input fields . Just provide your username and password is not enough.

Solutions:

  1. get all these fields and send them out together using PHP
  2. use some library which can simulate browser, then u can only provide username and password when logging in. This would be a little slow, but NOT the bottleneck of your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM