N.B: I have viewed Login with PHP curl and CSRF token and cURL CSRF Token, Login with CURL php and CSRF token and then some before posting.
I am creating a system which has a function (if it works) to analyse data from another website. This website requires login with a user, password & csrf token. See below for the code.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) die(curl_error($ch));
$doc = new DOMDocument();
$doc->loadHTML($response);
$token = $doc->getElementsByTagName("csrf")->attributes->getNamedItem("value")->value[0];
echo "TOKEN: {$token} ";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_POST, true);
$params = array(
'username' => $username,
'password' => $password,
'csrf' => $token
);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_exec($ch);
if (curl_errno($ch)) print curl_error($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
$html = curl_exec($ch);
print("<br />HTML: ".$html);
if (curl_errno($ch)) print curl_error($ch);
curl_close($ch);
I have slightly modified scripts from the above questions but am receiving these errors:
Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 24 in /home/dlip/subdomains$/eportaltest.website.com/public_html/ticket_load.php on line 18
Warning: DOMDocument::loadHTML(): Unexpected end tag : form in Entity, line: 76 in /home/dlip/subdomains$/eportaltest.website.com/public_html/ticket_load.php on line 18
Warning: DOMDocument::loadHTML(): Tag nav invalid in Entity, line: 124 in /home/dlip/subdomains$/eportaltest.website.com/public_html/ticket_load.php on line 18
Warning: DOMDocument::loadHTML(): Tag section invalid in Entity, line: 140 in /home/dlip/subdomains$/eportaltest.website.com/public_html/ticket_load.php on line 18
Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 176 in /home/dlip/subdomains$/eportaltest.website.com/public_html/ticket_load.php on line 18
Following instructions on the above questions, I've tried also using
$doc->loadHTML(htmlentities($response))
to no avail.
Does anyone have any clue whats going wrong? I understand it may be to do with the website, but how do I get around it?
Thanks :)