I am trying to extract the CSRF-token from a website to enable auto-login for my members on that page through credentials that I am sending via a POST-request. Unfortunately, that token is contained in the value of a hidden input field with the name "__csrf_token".
I have used the following code to successfully extract the value of the input field with the name "email", however when I use it on the above mentioned token field it just doesn't return a value.
<?php
$ch = curl_init("https://www.example.com/login.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$response = curl_exec($ch);
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($response);
$tags = $dom->getElementsByTagName('input');
for($i = 0; $i < $tags->length; $i++) {
$grab = $tags->item($i);
if($grab->getAttribute('name') === '__csrf_token') {
$token = $grab->getAttribute('value');
}
}
echo $token;
?>
Do you have any idea why the search for the mentioned name doesn't return a value?
Thanks! (Edit: Typo)