LoginSignup
29
30

More than 5 years have passed since last update.

無効な証明書なサイトに、file_get_contents する方法

Last updated at Posted at 2016-11-30

開発環境で自己署名しているhttps環境において、file_get_contentsすると、

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 xxxxx

というエラーが表示されます。
証明書入れてくれよと思うのですが、導入できない時もあります。その場合は、optionを付与することで回避できます。

$url = "https://xxxxxx";
$options['ssl']['verify_peer']=false;
$options['ssl']['verify_peer_name']=false;
$response = file_get_contents($url, false, stream_context_create($options));

PHP5.6.15で動作しました。このあたりも目を通しておくとよいと思います。

29
30
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
30