Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get SSL working in fsockopen?
    text
    copied!<p>I'm running PHP 5.2.6 on Windows, I have <code>extension=php_curl.dll</code> and <code>extension=php_openssl.dll</code> uncommented in php.ini; as such I can see the following in <code>phpinfo</code>:</p> <pre><code>curl cURL support enabled cURL Information libcurl/7.16.0 OpenSSL/0.9.8g zlib/1.2.3 openssl OpenSSL support enabled OpenSSL Version OpenSSL 0.9.8g 19 Oct 2007 </code></pre> <p>I'm not sure that having cURL enabled is vital to this, but since it mentioned OpenSSL I thought I'd include it here anyway for completeness.</p> <hr> <p>What I want to do is simple: make a POST request to another server over SSL using <code>fsockopen</code>.<br> My code so far is this:</p> <pre><code>$host = 'www.redacted.com'; $data = 'user=redacted&amp;pass=redacted&amp;action=redacted'; $response = ""; if ( $fp = fsockopen("ssl:{$host}", 443, $errno, $errstr, 30) ) { $msg = 'POST /wsAPI.php HTTP/1.1' . "\r\n"; $msg .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; $msg .= 'Content-Length: ' . strlen($data) . "\r\n"; $msg .= 'Host: ' . $host . "\r\n"; $msg .= 'Connection: close' . "\r\n\r\n"; $msg .= $data; if ( fwrite($fp, $msg) ) { while ( !feof($fp) ) { $response .= fgets($fp, 1024); } } fclose($fp); } else { $response = false; } </code></pre> <p>This works fine of course if I just pass in <code>$host</code> and use port 80. But I really need to send this over SSL, and right now it's not working. <code>$response</code> gets set to <code>false</code>, <code>$errno</code> stays at <code>0</code>, and <code>$errstr</code> gets set to <code>php_network_getaddresses: getaddrinfo failed: No such host is known.</code>. I know that it's not an issue of the server being down, or a typo in the host name, etc., because it DOES work if I go over port 80 unsecurely. The problems only start when I try to switch to SSL.</p> <p>What do I do to get this working?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload