Establish a port 80 connection with www.example.com in PHP
Description
The following code shows how to establish a port 80 connection with www.example.com.
Example
<?php//from w w w.jav a 2 s . co m
// Establish a port 80 connection with www.example.com
$http = fsockopen("www.example.com",80);
// Send a request to the server
$req = "GET / HTTP/1.1\r\n";
$req .= "Host: www.example.com\r\n";
$req .= "Connection: Close\r\n\r\n";
fputs($http, $req);
// Output the request results
while(!feof($http))
{
echo fgets($http, 1024);
}
// Close the connection
fclose($http);
?>
The code above generates the following result.