Today i found this very cool tutorial regarding the using of using ssl with PHP.
I’ll copy here the most interesting of it.
HTTP with PHP Sockets
// don’t need to specify http, it’s the default protocol
$hostname = “www.google.com”;
$port = 80;
// create and configure the client socket
$fp = fsockopen($hostname, $port); // optional: $error_number, $error_string, $connect_timeout
if ($fp) {
stream_set_timeout($fp, 30); // seconds to wait for i/o operations
// send request headers
fwrite($fp, “GET / HTTP/1.1\r\n”);
fwrite($fp, “Host: $hostname\r\n”);
fwrite($fp, $additional_headers); // Accept, User-Agent, Referer, etc.
fwrite($fp, “Connection: close\r\n”);
// read response
$response = “”;
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
echo $response;
// close the socket
fclose($fp);
}
recent comments