Use PHP streams.

Replaced manual exec of openssl with sed to use
PHP's SSL streams and client certificate capture
functionality. Also, put code into a function
so that it's not just a standalone script.