OpenSSL DOMDocument problem

0

I'm trying to get information from a site using DOMDocument but it's giving an error.

DOMDocument::loadHTMLFile(): SSL operation failed with code 1. 
OpenSSL Error messages: error:14090086:SSL 
routines:ssl3_get_server_certificate:certificate verify failed    



 $html = new DOMDocument();
 $html->loadHTMLFile("https://sistemasweb.sefaz.ba.gov.br/sistemas/DTE/Contribuinte/SSL/ASLibrary/Login");
 $dado = $html->getElementsByTagName('__EVENTVALIDATION');
 echo $dado;
    
asked by anonymous 08.12.2017 / 16:36

1 answer

0

The problem is the address certificate link , it is invalid, but can also occur, even if they correct the site, your PHP does not have the certificates configured, for the future perhaps try this link , which would look like:

$context = stream_context_create(array(
    "ssl"=>array(
        "cafile" => "/path/cacert.pem",
        "verify_peer"=> true,
        "verify_peer_name"=> true
    )
));

libxml_set_streams_context($context);

Or configure php.ini properly:

openssl.cafile=/path/cacert.pem

And restart Apache or Nginx. However it is as it said, the above solutions will not work, they are for when the site you are trying to access is with the corrected certificate, for now you can disable SSL checking like this:

$context = stream_context_create(array(
    "ssl"=>array(
        'verify_peer' => false,
        'verify_peer_name' => false
    )
));

libxml_set_streams_context($context);

$html = new DOMDocument();
$html->loadHTMLFile("https://sistemasweb.sefaz.ba.gov.br/sistemas/DTE/Contribuinte/SSL/ASLibrary/Login");
$dado = $html->getElementsByTagName('__EVENTVALIDATION');

echo $dado;

If libxml_set_streams_context does not work, you can try changing the approach to:

$context = stream_context_create(array(
    "ssl"=>array(
        'verify_peer' => false,
        'verify_peer_name' => false
    )
));

$conteudosite = file_get_contents("https://sistemasweb.sefaz.ba.gov.br/sistemas/DTE/Contribuinte/SSL/ASLibrary/Login", false, $context);

$html = new DOMDocument();
$html->loadHTML($conteudosite);

$dado = $html->getElementsByTagName('__EVENTVALIDATION');

echo $dado;
    
08.12.2017 / 16:55