maxdachs maxdachs - 1 month ago 28
PHP Question

PHP PhantomJS ignoring SSL certificate

I want to parse a HTTPS webpage, but it's blank when I do it.
So I think it has something to do with the SSL certificate.
How can I ignore this?

I'm using php-phantomjs.

Answer

As seen in the question PhantomJS failing to open HTTPS site, you may need to add the following commandline options to fix SSL/TLS problems:

phantomjs --ssl-protocol=any --ignore-ssl-errors=true --web-security=false script.js

The usage in php-phantomjs is a little different, but you can use either:

$client = Client::getInstance();
$client->getEngine()->addOption('--ssl-protocol=any');
$client->getEngine()->addOption('--ignore-ssl-errors=true');
$client->getEngine()->addOption('--web-security=false');

or load a config.json file like that:

$client->getEngine()->addOption('--config=/path/to/config.json');

config.json:

{
    "sslProtocol": "any",
    "ignoreSslErrors": true,
    "webSecurityEnabled": false
}