Forum Moderators: coopster
but it only works for 200 type, If the site does not resolve it just stays blank. Ideally I would put a switch statement in to allow for mutliple types.
Is there a problem with my IF statement or something else more sinister.
Cheers
#############
function remote_file_exists($url)
{
$head = "";
$url_p = parse_url($url);
if (isset ($url_p["host"]))
{
$host = $url_p["host"];
}
else
{
return FALSE;
}
if (isset ($url_p["path"]))
{
$path = $url_p["path"];
}
else
{
$path = "";
}
$fp = fsockopen ($host, 80, $errno, $errstr, 20);
if (!$fp)
{
return FALSE;
}
else
{
$parse = parse_url($url);
$host = $parse['host'];
fputs($fp, "HEAD ".$url." HTTP/1.1\r\n");
fputs($fp, "HOST: ".$host."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
$headers = "";
while (!feof ($fp))
{
$headers .= fgets ($fp, 128);
}
}
fclose ($fp);
echo htmlentities($headers);
if(ereg("200 OK", $headers, $regs))
{
print "200 = OK";
}
else
{
print "not 200";
}
}
$url = "http://www.google.co.uk";
remote_file_exists($url);
?>
[php.net...]