Rifts Posted November 25, 2014 Share Posted November 25, 2014 Hey guys I'm trying to log into this website using curl. I did some reading and think I'm pretty close but I cant get the login working It just returns nothing. there is a commented out part which is the page i'm trying to load after I successfully login. <? $username = 'xxxxxxx'; $password = 'xxxxxxx'; $postinfo = "username=".$username."&password=".$password; $cookie="cookie.txt"; $ch = curl_init(); // extra headers $headers[] = "Accept: */*"; $headers[] = "Connection: Keep-Alive"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_URL, 'https://weblogin.asu.edu/cas/login'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); $data = curl_exec($ch); if (curl_error($ch)) { echo curl_error($ch); } echo $data; curl_close($ch); // //page with the content I want to grab after logging in (test after login works) // curl_setopt($ch, CURLOPT_URL, "https://webapp4.asu.edu/myasu/"); // curl_setopt($ch, CURLOPT_POST, false); // $data = curl_exec($ch); // if (curl_error($ch)) { // echo curl_error($ch); // } ?> I'm not sure but I think im maybe missing some other parts the form needs? How do I see exactly what I need to send? Quote Link to comment https://forums.phpfreaks.com/topic/292694-need-some-help-trying-to-use-curl/ Share on other sites More sharing options...
QuickOldCar Posted November 25, 2014 Share Posted November 25, 2014 (edited) I do see some hidden values their form as well <input type="hidden" name="lt" value="LT-124551-2fwqfTISmFTdVpZurniEq1EZD5bVqO" /> <input type="hidden" name="execution" value="e1s1" /> Try this. <?php $username = 'xxxxxxx'; $password = 'xxxxxxx'; $postinfo = array( "username" => $username, "password" => $password ); //now an array $fields = http_build_query($postinfo); //builds the query $cookie = "cookie.txt"; $ch = curl_init(); // extra headers $headers[] = "Accept: */*"; $headers[] = "Connection: Keep-Alive"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_URL, 'https://weblogin.asu.edu/cas/login'); curl_setopt($ch, CURLOPT_POST, count($postinfo)); //counts the array values curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); //fields added curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); $data = curl_exec($ch); if (curl_error($ch)) { echo curl_error($ch); } echo $data; curl_close($ch); //page with the content I want to grab after logging in (test after login works) /* curl_setopt($ch, CURLOPT_URL, "https://webapp4.asu.edu/myasu/"); curl_setopt($ch, CURLOPT_POST, false); $data = curl_exec($ch); if (curl_error($ch)) { echo curl_error($ch); } */ ?> Edited November 25, 2014 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/292694-need-some-help-trying-to-use-curl/#findComment-1497571 Share on other sites More sharing options...
Rifts Posted November 25, 2014 Author Share Posted November 25, 2014 (edited) Trying your code echos back the empty login form and page minus the styling. also what about the hidden vaules? Edited November 25, 2014 by Rifts Quote Link to comment https://forums.phpfreaks.com/topic/292694-need-some-help-trying-to-use-curl/#findComment-1497577 Share on other sites More sharing options...
QuickOldCar Posted November 25, 2014 Share Posted November 25, 2014 Not sure what is needed. The hidden values could be required, which the value of lt changes each visit. Or they could even be bot traps, no idea. It seems to me they make efforts to prevent what you are attempting. Quote Link to comment https://forums.phpfreaks.com/topic/292694-need-some-help-trying-to-use-curl/#findComment-1497579 Share on other sites More sharing options...
Rifts Posted November 25, 2014 Author Share Posted November 25, 2014 dang oh well Quote Link to comment https://forums.phpfreaks.com/topic/292694-need-some-help-trying-to-use-curl/#findComment-1497580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.