Jump to content

Need some help trying to use curl


Rifts

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/292694-need-some-help-trying-to-use-curl/
Share on other sites

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);
}
*/
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.