Outputting the Status Lines Returned by Web Servers : fsockopen « File Directory « PHP






Outputting the Status Lines Returned by Web Servers

 
<html>
<head>
<title>Outputting Server Status Lines</title>
</head>
<body>
<div>
<?php
$to_check = array (
          "www.google.com" => "/index.html",
          "www.html.com"    => "/notthere.html",
          "www.java.com"   => "/nohost.html"
      );

foreach ( $to_check as $host => $page ) {
  print "<p>";
  $fp = @fsockopen( "$host", 80, $errno, $errdesc, 10);
  print "Trying $host<br/>";
  if ( ! $fp ) {
    print "Couldn't connect to $host:<br/>";
    print "Error: $errno<br/>";
    print "Desc: $errdesc<br/>";
  } else {
    print "Trying to get $page<br/>";
    fputs( $fp, "HEAD $page HTTP/1.0" );
    fputs( $fp, "Host: $host" );
    fputs( $fp, "\r\n" );
    print fgets( $fp, 1024 );
    fclose( $fp );
  }
  print "</p>\n";
}

?>
</div>
</body>
</html>
  
  








Related examples in the same category

1.fsockopen() function establishes a socket connection, TCP or UDP.
2.fsockopen.php
3.SSL Streams
4.Sockets Are Files
5.Scan a server
6.Retrieving a Web Page Using fsockopen()