public function getDownloadXmlCaptcha() {
if (session_status() == PHP_SESSION_NONE)
session_start();
// Passo 1
//link temporário
//Link Atual
$cookie = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'cookies1.txt';
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
//$verbose = fopen('log.txt', 'w+');
//curl_setopt($ch, CURLOPT_STDERR, $verbose);
//curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
$html = curl_exec($ch);
$document = new DOMDocument();
$document->loadHTML($html);
$viewstate = $document->getElementById('__VIEWSTATE')->getAttribute('value');
$stategen = $document->getElementById('__VIEWSTATEGENERATOR')->getAttribute('value');
$eventValidation = $document->getElementById('__EVENTVALIDATION')->getAttribute('value');
$token = $document->getElementById('ctl00_ContentPlaceHolder1_token')->getAttribute('value');
$captchaSom = $document->getElementById('ctl00_ContentPlaceHolder1_captchaSom')->getAttribute('value');
preg_match('~<img id=\"ctl00_ContentPlaceHolder1_imgCaptcha\" src=\"(.*)\" ~', $html, $_captcha);
$_SESSION['viewstate'] = $viewstate;
$_SESSION['stategen'] = $stategen;
$_SESSION['eventValidation'] = $eventValidation;
$_SESSION['token'] = $token;
$_SESSION['captchaSom'] = $captchaSom;
$captcha = $_captcha[1];
curl_close($ch);
//fclose($verbose);
return $captcha;
}
e o erro é o seguinte:
Fatal error: Call to a member function getAttribute() on null in C:\xampp\htdocs\nfe\src\DownloadNFeSefaz.php on line 243