在null上调用成员函数getNamedItem()

I'm trying to make a tool that will get the time someone needs to work. The login is secured with an CSRF token so I need to get that first before I can login.

This is the script what i'm using at the moment:

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

  $username = "jules.kreutzer";
  $password = "jules";
  $url = "planner.a-mac.nl";
  $cookie= "koekje.txt";
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/'.$cookie);
  curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/'.$cookie);

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $response = curl_exec($ch);

  if (curl_errno($ch)) die(curl_error($ch));
  $doc = new DOMDocument();
  $doc->loadHTML("http://planner.a-mac.nl");
  $token = $doc->getElementByID("signin__csrf_token")->attributes->getNamedItem("value")->value;
  print_r($token);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  curl_setopt($ch, CURLOPT_POST, true);

  $params = array(
    'signin[username]' => $username,
    'signin[password]' => $password,
    'signin[_csrf_token]' => $token
  );
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));

  curl_exec($ch);

  if (curl_errno($ch)) print curl_error($ch);
  curl_close($ch);
?>

When I load this code in my webbrowser I get the following errors:

Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/test.php on line 22

Fatal error: Call to a member function getNamedItem() on null in /Applications/MAMP/htdocs/test.php on line 22

line 22 is:

  $token = $doc->getElementByID("signin__csrf_token")->attributes->getNamedItem("value")->value;

I was hoping someone could help me get the token so I can use it for the login.

You misspelled getElementById:

Change:

$token = $doc->getElementByID("signin__csrf_token")->attributes->getNamedItem("value")->value;

to:

$token = $doc->getElementById("signin__csrf_token")->attributes->getNamedItem("value")->value;