First off, I'm a complete novice as a web developer. I have a PHP function that handles a post request for HTTP, and it works great. I read a few places online that all I have to do to make that same function post to HTTPS is change the port I'm hitting from port 80 to port 443. So instead o开发者_高级运维f looking like this:
$fp = fsockopen($host, 80, $errno, $errstr, 30);
It would look like this:
$fp = fsockopen($host, 443, $errno, $errstr, 30);
Unfortunately, this change doesn't seem to be working. So my questions are these:
Is it true that all I have to change is the port number?
If there is more to do, than what is it I still need to do?
Please try to keep things in as simple terms as possible, since I am the first to admit I'm very new to this kind of stuff.
Thanks a ton everyone.
Is it true that all I have to change is the port number?
No
If there is more to do, than what is it I still need to do?
You have to negotiate an SSL connection and tunnel the HTTP request through it.
Don't try to do this with sockets. Use a library designed for it, such as cURL.
From php.net:
If OpenSSL support is installed, you may prefix the hostname with either ssl:// or tls:// to use an SSL or TLS client connection over TCP/IP to connect to the remote host.
Try prepending ssl:// to your $host (but also keeping port 443;
精彩评论