<?php
function check_file($host,$file)
{
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "HEAD /$file HTTP/1.1\r\n";// or $out = "HEAD /index.xxx HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$response = explode(" ",fgets($fp, 128));
fclose($fp);
return $response[2];
}
}
echo check_file('huikon.cn','index.php');
?>
本函数用于判断远程文件是否存在。