PHPLinkCheck

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • PHPLinkCheck

    Hi,
    folgendes Problem:
    von PHP verstehe ich so viel, dass wenn man mir erklärt wie ich den Code verwende (sprich was muss angegeben werden und wie kommt das raus), dann verstehe ich es halbwegs.

    Folgende Frage:
    Wie nutze ich folgendes (phplinkcheck)

    <?php

    function phpLinkCheck($url, $r = FALSE)
    {
    /* Purpose: Check HTTP Links
    * Usage: $var = phpLinkCheck(absoluteURI)
    * $var["Status-Code"] will return the HTTP status code
    * (e.g. 200 or 404). In case of a 3xx code (redirection)
    * $var["Location-Status-Code"] will contain the status
    * code of the new loaction.
    * See print_r($var) for the complete result
    *
    * Author: Johannes Froemter <j-f@gmx.net>
    * Date: 2001-04-14
    * Version: 0.1 (currently requires PHP4)
    */

    $url = trim($url);
    if (!preg_match("=://=", $url)) $url = "http://$url";
    $url = parse_url($url);
    if (strtolower($url["scheme"]) != "http") return FALSE;

    if (!isset($url["port"])) $url["port"] = 80;
    if (!isset($url["path"])) $url["path"] = "/";

    $fp = fsockopen($url["host"], $url["port"], &$errno, &$errstr, 30);

    if (!$fp) return FALSE;
    else
    {
    $head = "";
    $httpRequest = "HEAD ". $url["path"] ." HTTP/1.1\r\n"
    ."Host: ". $url["host"] ."\r\n"
    ."Connection: close\r\n\r\n";
    fputs($fp, $httpRequest);
    while(!feof($fp)) $head .= fgets($fp, 1024);
    fclose($fp);

    preg_match("=^(HTTP/\d+\.\d+) (\d{3}) ([^\r\n]*)=", $head, $matches);
    $http["Status-Line"] = $matches[0];
    $http["HTTP-Version"] = $matches[1];
    $http["Status-Code"] = $matches[2];
    $http["Reason-Phrase"] = $matches[3];

    if ($r) return $http["Status-Code"];

    $rclass = array("Informational", "Success",
    "Redirection", "Client Error",
    "Server Error");
    $http["Response-Class"] = $rclass[$http["Status-Code"][0] - 1];

    preg_match_all("=^(.+): ([^\r\n]*)=m", $head, $matches, PREG_SET_ORDER);
    foreach($matches as $line) $http[$line[1]] = $line[2];

    if ($http["Status-Code"][0] == 3)
    $http["Location-Status-Code"] = phpLinkCheck($http["Location"], TRUE);

    return $http;
    }
    }

    ?>
    Gruß

    Kischon

  • #2
    PHP-Code:
    $var phpLinkCheck("www.test.de");

    echo 
    $var["Status-Line"];
    echo 
    $var["HTTP-Version"];
    echo 
    $var["Status-Code"];
    echo 
    $var["Reason-Phrase"]; 
    Zuletzt geändert von Moqui; 30.08.2003, 19:54.
    tata
    moqui

    [COLOR=red]Ich will keine unaufgeforderten Mails über PHP Fragen. Es gibt ein Forum hier! Und ich bin nicht Scripter für jeden, der mir ne Mail schreibt![/COLOR]

    Kommentar


    • #3
      Danke - schon mal ein Stück weiter.
      Und wie gibt er das Ergebnis aus?
      Und kann man das "automatisieren" á la
      Link XY
      - wenn okay, dann darauf weiterleiten
      - wenn nicht okay, dann Email an Webmaster der eigenen Seite
      und ein Entschuldigung ;-)

      Gruß

      Ilan
      Gruß

      Kischon

      Kommentar


      • #4
        PHP-Code:

        // Variable, die die URL beinhaltet
        $url "www.test.de";

        // aufruf deiner Funktion und übergabe der Werte an $var
        $var phpLinkCheck($url);

        // überprüfen, ob $var["Reason-Phrase"] OK gibt
        if($var["Reason-Phrase"] == "OK") {

        // wenn ja, dann weiterleitung
        header("Location: ".$url);
        } else {

        // wenn nein, dann Fehler!
        echo "nix wars!";

        aber ich hab schon bugs in dem script gefunden.

        wenn die domain nicht erreichbar ist, gibs fehlermeldungen.

        Man sollte mal ne Fehlerbehandlung reinbauen und maln paar @ voranstellen.

        EDIT:
        besser so?
        Zuletzt geändert von Moqui; 30.08.2003, 20:07.
        tata
        moqui

        [COLOR=red]Ich will keine unaufgeforderten Mails über PHP Fragen. Es gibt ein Forum hier! Und ich bin nicht Scripter für jeden, der mir ne Mail schreibt![/COLOR]

        Kommentar


        • #5
          Jetzt verstehe ich nix mehr :-(

          Kannst du mir den Code korrigieren und modifizieren?

          Gruß

          Ilan
          Gruß

          Kischon

          Kommentar


          • #6
            warte ich kommentier dir das script mal aus....
            tata
            moqui

            [COLOR=red]Ich will keine unaufgeforderten Mails über PHP Fragen. Es gibt ein Forum hier! Und ich bin nicht Scripter für jeden, der mir ne Mail schreibt![/COLOR]

            Kommentar

            Lädt...
            X