I'm using php curl to try and log in to a form that is using a token. I've tried different combinations, some of them from StackOverflow but can't seem to get it right.
Here is my code so far:
$html = new simple_html_dom();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.de/My-account');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, '');
$response = curl_exec($ch);
$html->load($response);
foreach($html->find('input[name="jtl_token"]') as $content){
$token = $content->value;
}
$credentials = [
'jtl_token' => $token,
'email' => 'my@email.com',
'passwort' => 'password',
'login' => 1
];
curl_setopt($ch, CURLOPT_URL, 'https://www.example.de/My-account');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($credentials));
curl_setopt($ch, CURLOPT_COOKIEFILE, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
I'm using simple_html_dom class to get the token and then I just try to send it to that page but it doesn't work, the response is the page before log in.
Thank you.