<? function check_url($url) { if (eregi( '^http://', $url)) { $urlarray = parse_url($url); if (!$urlarray[port]) $urlarray[port] = '80'; if (!$urlarray[path]) $urlarray[path] = '/'; $sock = fsockopen($urlarray[host], $urlarray[port], &$errnum, &$errstr); if (!$sock) $res = 'dns'; else { $dump .= "get $urlarray[path] http/1.1\r\n"; $dump .= "host: $urlarray[host]\r\nconnection: close\r\n"; $dump .= "connection: close\r\n"; fputs($sock, $dump); while ($str = fgets($sock, 1024)) { if (eregi("^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*", $str)) $res[code] = trim(eregi_replace('^http/[0-9]+.[0-9]+([0-9]{3})[a-z ]*', "\\1", $str)); if (eregi("^content-type: ", $str)) $res[contenttype] = trim(eregi_replace("^content-type: ", "", $str)); } fclose($sock); flush(); return $res[code]; } } else $res = "n/a"; return $res; } ?>
|
Категория: PHP | Добавил: webmaster (2006-12-06)
|
Просмотров: 359
| Рейтинг: 0.0 |
|