Hello,
I'm try to find code that will return the status code of some url. for example: 200 (if the page is OK), 404 (Not Found), 500 (Internal Server Error) and ect -
http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html

I found the following code but I don't know how to keep the status code (only the number) in variable...
?

$host = "www.cnn.com";
$uri = '/';
$fp = fsockopen("$host", 80, $errno, $errstr, 30);

if(!$fp)
{
   echo "$errstr ($errno)<br />\n";
   return;
} 
else
{
   fwrite($fp,"HEAD $uri HTTP/1.0\r\n");
   fwrite($fp,"Host: $host\r\n");
   fwrite($fp,"Connection: Close\r\n");
   fwrite($fp,"\r\n");
   while (!feof($fp)) {
		$content .= fgets($fp, 128);
	}
   fclose($fp);
}
echo '<p>Results for <a href="\"http://$host$uri\">http://$host$uri</a></p>';
echo '<textarea cols="55" rows="9" wrap="off">';
echo $content;
echo '</textarea><br /><hr /><br />';

    It's the three-digit number after the first space on the first line.

    $space = substr($content, strpos($content, ' ')+1, 3);

      Thanks Weedpacket!
      its working fine now.

      one more thing - the script ask me to enter url+uri (the part of the URL after the domain name- after the "/" ). what do I need to change in the code so all I'll need to put is just the full page url that I wish to check and get its status code ?

        Write a Reply...