Mega Code Archive

 
Categories / Php / File Directory
 

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>