2015-09-28 48 views
3

我想在https中獲取我的頁面的結果在php變量中,但fopen函數返回false;Fopen接受自簽名證書

我覺得這個錯誤可以通過SSL certifacte這是自是產品簽署

fopen("https://192.168.1.1:8443", "rb")) 

Warning: fopen(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

它是一個PHP的SSL配置接受所有的證書?

回答

6

看到Error when loading external xml file with php via https : SSL3_GET_SERVER_CERTIFICATE

出口自簽名證書PEM編碼並將它添加到CA-bundle.crt(或者如果沒有CA-bundle.crt然而,僅僅重命名導出文件)

然後使用

$context = stream_context_create(array('ssl'=>array(
    'verify_peer' => true, 
    'cafile' => '/path/to/ca-bundle.crt' 
))); 
$fd = fopen("https://192.168.1.1:8443", "rb", false, $context); 

看到SSL context optionsstream_context_create

6

入住這一點 - http://php.net/manual/en/function.stream-context-create.php

<?php 
$opts=array(
    "ssl"=>array(
     "verify_peer"=>false, 
     "verify_peer_name"=>false, 
    ), 
); 

$response = fopen("https://192.168.1.1:8443", false, stream_context_create($opts)); 

echo $response; ?> 
+0

它應該是'$響應=的fopen( 「https://192.168.1.1:8443」, 'RB',假,stream_context_create($ OPTS));'你跳過1個參數 – Eugene