Skip to content
PHP Logo

What are some common issues when using PHP to parse HTML from SSL websites with invalid certificates?

When parsing HTML from SSL websites with invalid certificates in PHP, a common issue is that the script may fail to connect to the website due to the certificate validation error. To solve this, you can disable SSL certificate verification in your PHP script using the "stream_context_create" function with the "ssl" context option set to "verify_peer" and "verify_peer_name" both set to false.

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

$html = file_get_contents('https://example.com', false, $context);
echo $html;