Pastrare sesiuni active la trimiterea datelor cu cURL
Scris: Mar Mai 29, 2018
Salut, vreau sa trimit date catre un formular cu cURL dar am o problema, ca sa accesez formularul trebuie sa fiu logat iar la trimiterea datelor imi arata ca sunt delogat, de ce? Si cum as putea pastra sesiunile active atunci cand trimit datele cu cURL?
Image: imgur.com/a/iWtb3LJ
Cod:
Image: imgur.com/a/iWtb3LJ
Cod:
Cod: SelectaĊ£i tot
<?php
//receives string $html with html code
//returns the value of the html input with name of $name
function getInpValName($html, $name){
$re ='no val';
$dom = new DomDocument;
//load the html into the object
error_reporting(~E_WARNING); // to not output warning errors
$dom->loadHTML($html);
$elms = $dom->getElementsByTagName('input');
foreach($elms as $elm){
if($elm->getAttribute('name') ==$name){
$re = $elm->getAttribute('value');
break;
}
}
return $re;
}
//Test
$html = file_get_contents('http://localhost/whmcs/clientarea.php?action=changepw');
// echo getInpValName($html, 'token');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/whmcs/clientarea.php?action=changepw");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
// $str = substr(str_shuffle(str_repeat("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 5)), 0, 8);
$data = array(
'token' => "". getInpValName($html, 'token') ."",
'existingpw' => "Pass1*",
'newPassword1' => "Pass2*",
'newPassword2' => "Pass2*"
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo '<pre>';
print_r($data);
echo '<br />';
print_r($info);
echo '</pre>';
echo '<br />';
echo $output;
?>