![](/img/trans.png)
[英]php,mqtt: stream_socket_client(): unable to connect to <server><port>
[英]PHP stream_socket_client(): unable to connect to https
我剛剛注意到在Wordpress中發現的新漏洞,並嘗試使用以下代碼修復該漏洞(但取得了成功)
<?php
$url = 'https://mywebip/wp-login.php?action=lostpassword';
$data = 'user_login=admin&redirect_to=&wp-submit=Get+New+Password';
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Host: mailserver\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ". strlen($data) ."\r\n",
'method' => 'POST',
'content' => $data,
'ssl'=>array('verify_peer'=>true, 'capath'=>'/etc/ssl/certs')
)
);
$context = stream_context_create($options);
//$result = file_get_contents($url, false, $context);
$fp = stream_socket_client($url, $errno, $errstr, 30);
//stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
$fp = fopen($url, 'r', false, $context);
if ($fp === FALSE) { /* Handle error */ }
var_dump($result);
?>
我得到的錯誤日志如下所示:
PHP Warning: stream_socket_client(): unable to connect to https://mywebip/wp-login.php?action=lostpassword (Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?) in /home/jorge/Escritorio/joomla.php on line 18
PHP Warning: fopen(): Peer certificate CN=`website` did not match expected CN=`mywebip' in /home/jorge/Escritorio/joomla.php on line 21
PHP Warning: fopen(): Failed to enable crypto in /home/jorge/Escritorio/joomla.php on line 21
PHP Warning: fopen(https://mywebip/wp-login.php?action=lostpassword): failed to open stream: operation failed in /home/jorge/Escritorio/joomla.php on line 21
其中, mywebip
代表托管我的網站以及website
和mailserver
的實際IP,服務的DNS方向。
謝謝。
通過套接字,您沒有指定協議。
http://php.net/stream_socket_client
第一個參數:
remote_socket
要連接的套接字地址。
地址只是mywebip
。
您應該改用CURL。
參見http://php.net/manual/en/curl.examples.php
另一個問題(使用fopen()
可以處理帶有協議的流!)是您的網絡服務器頒發的格式錯誤的證書。
使用此服務調試Web服務器證書的問題:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.