TLS is the correct name, but most people still call it SSL. In PHP, you can make this connection using CURL .
With the TLS / SSL client, you only need the public key to verify the remote host. This public key is simply public, it does not matter if it gets into the attacker. On the server side, Apache has access to both the public and private keys. These keys are protected by common file permissions. On * nix systems, these keys are usually stored somewhere in /etc/ belonging to the Apache process, and best of all, chmod 400 .
The easiest authentication method for clients is a simple username / password. You can use SSL to authenticate both the client and server. This will require you to keep the secret key somewhere where your PHP application has access, ideally outside of webroot with chmod 400 , but you can easily rename it to .php or put it in a folder with .htaccess that contains deny from all . On the server side, you can verify the client certificate using these environment variables .
If you just want to connect to TLS, not HTTP. Then you can use stream_context_set_option by setting Context Parameters :
<?php $context = stream_context_create(); $result = stream_context_set_option($context, 'ssl', 'local_cert', '/path/to/keys.pem'); // This line is needed if your cert has a passphrase $result = stream_context_set_option($context, 'ssl', 'passphrase', 'pass_to_access_keys'); $socket = stream_socket_client('tls://'.$host.':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); ?>
source share