phpbar.de logo

Mailinglisten-Archive

[php] AW: [php] linkchecker

[php] AW: [php] linkchecker

Matthias Klos matthias.klos_(at)_fh-gelsenkirchen.de
Wed, 25 Oct 2000 12:49:33 +0200


 Gibt es da noch Alternativen, oder
> Verbesserungsvorschläge?
>

Versuchs mal damit. Kannst du dir aber auch noch anpassen. Leider weis ich
den Autor nicht mehr.
Die F habe ich aus einem Script das sich linkcheck nennt. Anbei noch eine
Liste mit Statuscodes.

///// Statuscodes ////////////////

$text['N/A'] = "Ikke HTTP";
$text[OK]    = "Valid hostname";
$text[FEJL]  = "Invalid hostname";
$text[Dead]   = "No responce";
$text[100]   = "Continue";
$text[101]   = "Switching Protocols";
$text[200]   = "OK";
$text[201]   = "Created";
$text[202]   = "Accepted";
$text[203]   = "Non-Authoritative Information";
$text[204]   = "No Content";
$text[205]   = "Reset Content";
$text[206]   = "Partial Content";
$text[300]   = "Multiple Choices";
$text[301]   = "Moved Permanently";
$text[302]   = "Found";
$text[303]   = "See Other";
$text[304]   = "Not Modified";
$text[305]   = "Use Proxy";
$text[307]   = "Temporary Redirect";
$text[400]   = "Bad Request";
$text[401]   = "Unauthorized";
$text[402]   = "Payment Required";
$text[403]   = "Forbidden";
$text[404]   = "Not Found";
$text[405]   = "Method Not Allowed";
$text[406]   = "Not Acceptable";
$text[407]   = "Proxy Authentication Required";
$text[408]   = "Request Timeout";
$text[409]   = "Conflict";
$text[410]   = "Gone";
$text[411]   = "Length Required";
$text[412]   = "Precondition Failed";
$text[413]   = "Request Entity Too Large";
$text[414]   = "Request-URI Too Long";
$text[415]   = "Unsupported Media Type";
$text[416]   = "Requested Range Not Satisfiable";
$text[417]   = "Expectation Failed";
$text[500]   = "Internal Server Error";
$text[501]   = "Not Implemented";
$text[502]   = "Bad Gateway";
$text[503]   = "Service Unavailable";
$text[504]   = "Gateway Timeout";
$text[505]   = "HTTP Version Not Supported";

////// Die eigentliche F ///////////////////////

function check($url) {
   if (!eregi("^http://", $url)) {
      if (eregi("^mailto:", $url)) {
	     $url = trim(eregi_replace("^mailto:(.+)", "\\1", $url));
		 list($brugernavn, $host) = split("_(at)_", $url);
		 $dnsCheck = checkdnsrr($host,"MX");
		 if ($dnsCheck) $return[code] = "OK";
		 else $return[code] = "ERROR";
	  }
      else $return[code] = "N/A";
   }
   else {
      $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) $return[code] = "Død";
         else {
            $dump .= "GET $urlArray[path] HTTP/1.1\r\n";
            $dump .= "Host: $urlArray[host]\r\nConnection: close\r\n";
            $dump .= "Connection: close\r\n\r\n";
            fputs($sock, $dump);
	        while($str = fgets($sock, 1024)) {
	          if (eregi("^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*", $str))
$return[code]        = trim(eregi_replace("^http/[0-9]+.[0-9]+ ([0-9]{3})
[a-z ]*", "\\1", $str));
		       if (eregi("^Content-Type: ", $str))
$return[contentType] = trim(eregi_replace("^Content-Type: ", "", $str));
	        }
	        fclose($sock);
            flush();
         }
   }
	  return $return;
}


/////////// Zum Testen /////////

$url = http://www.wasauchimmer.de
$test=check($url);
while(list($k, $v) = each($test)) printf("typ=%s, value=%s<br>\n", $k, $v);
echo "$test";



php::bar PHP Wiki   -   Listenarchive