Чекер ссылок

Discussion in 'Болталка' started by Ziegel, 8 May 2012.

  1. Ziegel

    Ziegel New Member

    Joined:
    19 Jan 2012
    Messages:
    1
    Likes Received:
    0
    Reputations:
    0
    /del
     
    #1 Ziegel, 8 May 2012
    Last edited: 12 Oct 2012
  2. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    937
    Likes Received:
    355
    Reputations:
    58
    Что он должен проверять? Просто доступность ресурса?

    PHP:
    <?php
    set_time_limit
    (0);
    $linksFile "links.txt"// Файл с ссылками
    $linksArr file($linksFile);

    foreach (
    $linksArr as $link)
    {
        
    $host preg_replace("~http://|\/$~"""trim($link));
        
    $fp fsockopen($host80$errno$errstr);
        if (!
    $fp)
        {
            echo 
    "$errstr ($errno)<br>\n";
        }
        else 
        {
            
    $out "GET / HTTP/1.1\r\n";
            
    $out .= "Host: ".$host."\r\n";
            
    $out .= "Connection: Close\r\n\r\n";
            
            
    fwrite($fp$out);
            
    $res '';
            while (!
    feof($fp))
            {
                
    $res .= fgets($fp128);
            }
            
    fclose($fp);
            
            if (
    preg_match("~HTTP/\d\.\d 2\d+~"$res))
            {
                echo 
    "<font color=green size=5>Ok</font>, link <b>".$link."</b> is available<br>\r\n";
            }
            elseif (
    preg_match("~HTTP/\d\.\d 3\d+~"$res))
            {
                
    preg_match("~Location: .*~"$res$m);
                echo 
    "<font color=green size=5>Ok</font>, link <b>".$link."</b> is available, but moved ".$m[0]."<br>\r\n";
            }
            else
            {
                echo 
    "<font color=red size=5>Not ok</font>, link <b>".$link."</b> is not available :(<br>\r\n";
            }
            
    flush();
            
    ob_flush();
        }
    }
     
    #2 Skofield, 9 May 2012
    Last edited: 9 May 2012