mardi 27 janvier 2015

cURL login simulator gets no cookie response


I am new to cURL functions and while i understand what it should be doing, i am having a hard time making it work. I have a script building the variables and then calling a function to create a curl_init(); variable.


here is my try, what am i doing wrong (sorry for being vague) :



$loginUrl = 'http://ift.tt/15GaPy2';
$loginFields = array(
'URI'=>'https://www.link.htm',
'AUTHMETHOD'=>'UserPassword',
'Time'=>(strtotime(date('Y-m-d H:i:s')) * 1000)-10000),
'LOC'=>'en_US',
'usr_name'=>'clear_text_usrname%40domainname',
'usr_password'=>'clear_text_password',
'usr_check'=>'' //usr_check is the checkbox
//"remember my username" input on the page.
//Should i send it as well?
);
$login = $cURLclass->getUrl($loginUrl, $loginFields);


Where URI, AUTHMETHOD, Time and LOC are hardcoded hidden input fields that i have to match the same input (Time is the unix epoch time in miliseconds). the "%40" in the usr_name is used to recreate a "@", because cURL uses @ to declare filenames as far as i read on the subject.


Then, my getUrl function :



function getUrl($url, $vars='') {

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // BYPASS SSL VALIDATION; CANT GET FILE ON SERVER TO WORK WTV
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookies.txt');
$buffer = curl_exec($ch);
//echo curl_error($ch);
curl_close($ch);
return $buffer;
}


All in all the whole page, after authentification, should be dropped in the $login variable as far as i understand, and then should be ready for the next operation. This function already worked as far as i know but adding new variables (because the form on the page im trying to access as more inputs) simply doesn't allow it to work.


Thanks.


P.S. : It's all PHP


EDIT : Thank you Patrick LC for the clean editing i really appreciate the help.





Aucun commentaire:

Enregistrer un commentaire