I had this piece of code to get the likes of a particular Facebook page in production since years:
$url = 'https://graph.facebook.com/<facebook site id>';
echo json_decode(file_get_contents($url))->{'likes'};
Now we upgraded to PHP 5.6 and it stopped working with the following error message:
Warning: file_get_contents() [function.file-get-contents.php]: SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in <some page> on line 182
Warning: file_get_contents() [function.file-get-contents.php]: Failed to enable crypto in <some site> on line 182
Warning: file_get_contents(https://graph.facebook.com/<facebook site id>) [function.file-get-contents.php]: failed to open stream: operation failed in <some page> on line 182
Is there a simple way to fix this?
I know there is a referenced answer but this answer disables SSL verification and I don't want to implement a possible security hole!
CURLOPT_SSL_VERIFYPEER is set to TRUE by default starting with cURL 7.10
You could set it to FALSE again, although it would be wiser to set the CA certificates (see http://php.net/manual/en/function.curl-setopt.php for more info).
Also, keep in mind that file_get_contents will return FALSE on timeout, so it may be a good idea to :
- Set a lower timeout than the default php timeout of 0 seconds
- Handle any returns of FALSE
Related
I have a WordPress plugin that I created and it has stopped working because of a certificate error.
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
I contacted the inmotionhosting and they said the certificate was fine. The code in question is this:
$op = file_get_contents(plugins_url( '../PRTHSEL_Visualizer.html' , __FILE__ ));
It was suggested that I use an https request to get the file. I have searched but cannot find and answer on how to get a file contents within a WordPress plugin via https.
The problem was the file_get_contents() was given a url for a local file. Byt changing the path to a local it now works under PHP7. PHP 5 never verified the SSL by default but PHP7 does.
This question already has answers here:
file_get_contents(): SSL operation failed with code 1, Failed to enable crypto
(21 answers)
Closed 4 years ago.
I am developing a web page and I have a small problem with the YouTube API. I want to get all the information of any YouTube video, but I can not get the data. I have the following PHP code to make the request to the server:
Here is my Code:
$video_get_contents = file_get_contents('https://www.googleapis.com/youtube/v3/videos?part=snippet&id=J643lwa-BlM&key=AIzaSyATfzheNPybhDYRIgLwQw__rjE8XddZP8s');
$video_data = json_decode($video_get_contents);
$video_data_title = $video_data->items[0]->snippet->title;
echo $video_data_title;
When I run the previous code I do not get anything, and I do not know why. If I access the URL specified in the code, the JSON code is generated correctly.
When executing my code I get these errors:
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in C:\xampp\htdocs\beta.php on line 4
Warning: file_get_contents(): Failed to enable crypto in C:\xampp\htdocs\beta.php on line 4
Warning: file_get_contents(https://www.googleapis.com/youtube/v3/videos?part=snippet&id=J643lwa-BlM&key=AIzaSyATfzheNPybhDYRIgLwQw__rjE8XddZP8s): failed to open stream: operation failed in C:\xampp\htdocs\beta.php on line 4
Could you tell me if the PHP code is correct?
you cant access https url with the file_get_contents,
however for youtube API you can access it using the example in https://developers.google.com/youtube/v3/code_samples/php
and if you still want to access the json in your url, here is a similar question about how to access https with file get contents file_get_contents(): SSL operation failed with code 1. And more
After December 3, i cant send Emails whit smtp from php (Codeigniter), i have not changed anything, I do not know what is happening.
Does anyone know if there is any update that left some function obsolete in some version of PHP?
Message: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Filename: libraries/Email.php
Thanks for help!
I already solve this problem.
I realized that there is a lot of disinformation on the internet about this topic.
I hope this can be useful!
If you running PHP 5.3.7 or later.
Generate an vbs file from this file.
https://raw.githubusercontent.com/bagder/curl/master/lib/mk-ca-bundle.vbs
Open a Command Prompt as Administrator and run
C:>mk-ca-bundle.vbs
After finish that process you need to modify the php.ini.
openssl.cafile=C:\ca-bundle.crt
Restart the IIS web site and its all
I can't get a xml file to load.
This code works great:
$url = 'http://www.w3schools.com/xml/note.xml';
$xml = simplexml_load_file($url);
print_r($xml);
But this one
$url = 'https://www.boardgamegeek.com/xmlapi2/thing?id=105551';
$xml = simplexml_load_file($url);
print_r($xml);
doesn't work. I get this error:
Warning: simplexml_load_file(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /storage/content/59/113059/boardgamelevelup.com/public_html/index.php on line 19 Warning: simplexml_load_file(): Failed to enable crypto in /storage/content/59/113059/boardgamelevelup.com/public_html/index.php on line 19 Warning: simplexml_load_file(https://www.boardgamegeek.com/xmlapi2/thing?id=105551): failed to open stream: operation failed in /storage/content/59/113059/boardgamelevelup.com/public_html/index.php on line 19 Warning: simplexml_load_file(): I/O warning : failed to load external entity "https://www.boardgamegeek.com/xmlapi2/thing?id=105551" in /storage/content/59/113059/boardgamelevelup.com/public_html/index.php on line 19
The xml file from boardgamegeek works on other sites. Should I use a different php code to load that xml file?
short cookbook answer:
Download https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt and place that file on your server.
Add
$context = stream_context_create(array('ssl'=>array(
'verify_peer' => true,
'cafile' => '/path/to/ca-bundle.crt'
)));
libxml_set_streams_context($context);
to your script so it gets executed before simplexml_load_file().
Or - instead of the code above - set openssl.cafile=/path/to/ca-bundle.crt in your php.ini.
Very short explaination:
Your php version uses openssl to handle the https transport. openssl tries to verify whether the server really is who it claims to be. It does that by checking whether its certificate is trusted. A X.509 certificate contains some data about the owner and is signed by an issuer (itself having a certificate that is again signed and so on and on until a certificate where owner and issuer are identical -> self-signed/root certificate). A certificate is considered "trusted" if in that chain of certificates there is (at least) one certificate on which openssl "says": "ok, I have been instructed to trust this one". This instruction takes the form of (or can take the form of) "here's a file containing certificates that you're supposed to trust" (cafile).
The above code tells the libxml-wrapper of php to tell openssl where that cafile is when simplexml_load_file uses the https/openssl-wrapper.
And openssl.cafile=/path/to/ca-bundle.crt just sets it as default; unless instructed otherwise all openssl operations will use that file - including libxml/simple_xml_loadfile.
The ca-bundle.crt I've linked to is from a project that "claims" to provide the extracted root certificates as shipped with mozilla firefox. Regarding "claims": I have no reason to doubt that this really is the untampered root cert list; but you never know: You're putting your trust a) in this project and b) mozilla doing a good job and only putting trustworthy certificates in that list....
for more explaination see http://phpsecurity.readthedocs.org/en/latest/Transport-Layer-Security-%28HTTPS-SSL-and-TLS%29.html#php-streams
The work and example that #VolkerK displayed was excellent and simple.
While this method didn't work for me, I took it one step further and basically removed the security for the moment.
$context = stream_context_create(array('ssl'=>array(
'verify_peer' => false,
"verify_peer_name"=>false
)));
libxml_set_streams_context($context);
$sxml = simplexml_load_file($webhostedXMLfile);
Yes, this is bad practice, but sometimes you need a temp fix instead of messages like this:
Warning: simplexml_load_file(): SSL operation failed with code 1.
OpenSSL Error messages: error:14090086:SSL
routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in
/srv/www/resources/public_html/files/etc/file.php on line 150 Warning:
simplexml_load_file(): Failed to enable crypto in
/srv/www/resources/public_html/files/etc/file.php on line 150
I hope it helps someone else.
I recently found out that I have a huge amount of Facebook bots that are following my Facebook Fanpage. As a result I have lots of trouble interacting with my fans.
Thus I wanted to to remove all the bots from my page using that instruction:
Facebook API: Get fans of / people who like a page
Unfortunately when I use that code I get an error message:
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /Applications/XAMPP/xamppfiles/htdocs/schnooglestandalone/test.php on line 19
Warning: file_get_contents(): Failed to enable crypto in /Applications/XAMPP/xamppfiles/htdocs/schnooglestandalone/test.php on line 19
Warning: file_get_contents(http://www.facebook.com/plugins/fan.php?connections=100&id=251682891644217): failed to open stream: operation failed in /Applications/XAMPP/xamppfiles/htdocs/schnooglestandalone/test.php on line 19
This answer didnt help:
file_get_contents(): SSL operation failed with code 1. And more
As you can see, I am running the script from a local XAMPP Server. My Facebook page is german.
Thanks guys