I am trying to connect to a server using PHP script. The server is set by SSLv3, I think maybe I need use SSL_Write()
to process the message which will send to the server. But I do not find the related function in PHP. So, I wonder which function should I use.
What you are looking for is the TLS stream transport. There is no direct equivalent to the SSL_Write()
function; PHP does not implement a functional interface to SSL.
Here is a simple example of using the TLS transport to make a connection to an HTTPS web server. This is not an ideal application of the transport, as PHP already natively supports an HTTPS file wrapper; I'm simply using it here as an example of interacting with a publicly accessible TLS server.
$fh = stream_socket_client("tls://example.com:443", $errno, $errstr);
if ($fh === false) {
die("Failed to connect: error=$errno $errstr");
}
fwrite($fh, "GET / HTTP/1.1
Host: example.com
Connection: close
"\ );
while (!feof($fh)) {
print fgets($fh);
}
If you need to set specific options on the TLS connection, you can do so by creating a stream context (using stream_context_create()
) before making the connection. Refer to the PHP documentation for more details.