• 27-04-2022, 12:17:16
    #1
    Merhaba arkadaşlar,

    siteler.txt içindeki sitelerin hangileri 404 hatası veriyor, hangileri vermiyor tespit edip bunlarım 404 hatası verenlerini 404-siteler.txt, 404 hatası vermeyen site adreslerini ise temiz-siteler.txt içine alt alta yazdırmak istiyorum. Yapmak istediğim şeyde kısmen de başarılı oldum.

    siteler.txt dosyasına 20 tane sayfa adresi yazdım, bu sayfalardan 5 tanesi 404 hatası veriyor, kalan 15 tane hata vermeden 200 kodu döndürüyor.
    http status durumuna göre 404-siteler.txt dosyasına sadece 1 tane sayfa yazıp, kalan 404 sayfalarını da temiz-siteler.txt dosyasına yazdırıyor.

    Ben nerede hata yapıyorum?

    <?php
    $urloku = file("siteler.txt");
    for ($i = 0; $i < count($urloku); $i++) {
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $urloku[$i]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_exec($ch);
    $info = curl_getinfo($ch);
    
    if($info['http_code'] == "404"){
        $dosya404 = fopen("404-siteler.txt" , 'a+');
        fwrite ($dosya404 , $info['url']."\n");
        fclose ($dosya404);
        
    }else{
        $dosyatemiz = fopen("temiz-siteler.txt" , 'a+');
        fwrite ($dosyatemiz , $info['url']."\n");
        fclose ($dosyatemiz);
    }
    }
    ?>
  • 27-04-2022, 12:34:00
    #2
    Şöyle dener miisn hocam.

    <?php
    $urloku = file("siteler.txt");
    for ($i = 0; $i < count($urloku); $i++) {
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $urloku[$i]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_exec($ch);
    $info = curl_getinfo($ch);
    
    if($info['http_code'] == "404"){
    $dosya = fopen("404-siteler.txt" , 'a+');
    
    }else{
    $dosya = fopen("temiz-siteler.txt" , 'a+');
    }
    
    fwrite ($dosya , $info['url']."\n");
    fclose ($dosya);
    }
    ?>
  • 27-04-2022, 12:46:38
    #3
    omergunay adlı üyeden alıntı: mesajı görüntüle
    Şöyle dener miisn hocam.

    <?php
    $urloku = file("siteler.txt");
    for ($i = 0; $i < count($urloku); $i++) {
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $urloku[$i]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_exec($ch);
    $info = curl_getinfo($ch);
    
    if($info['http_code'] == "404"){
    $dosya = fopen("404-siteler.txt" , 'a+');
    
    }else{
    $dosya = fopen("temiz-siteler.txt" , 'a+');
    }
    
    fwrite ($dosya , $info['url']."\n");
    fclose ($dosya);
    }
    ?>
    Sorun çözülmedi, 20 sayfadan oluşan siteler.txt içindeki 5 tane 404 sayfasından 1 tanesini 404-siteler.txt yazdırıp, geri kalanları temiz-siteler.txt yazdırdı.
  • 27-04-2022, 13:03:11
    #4
    hocam onların http_code 404 geldiğine emin misin peki. Belki sen 404 düşünüyorsun onlar 301 gibi redirect geliyordur falan.
  • 27-04-2022, 13:16:23
    #5
    Buyrun hocam umarım çözebilmişimdir
    <?php
    
    $handle = fopen("siteler.txt", "r");
    if ($handle) {
        while (($line = fgets($handle)) !== false) {
    
    $html_brand = trim($line);
    $ch = curl_init();
    
    $options = array(
        CURLOPT_URL            => $html_brand,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER         => true,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_ENCODING       => "",
        CURLOPT_AUTOREFERER    => true,
        CURLOPT_CONNECTTIMEOUT => 120,
        CURLOPT_TIMEOUT        => 120,
        CURLOPT_MAXREDIRS      => 10,
    );
    curl_setopt_array( $ch, $options );
    $response = curl_exec($ch); 
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    
    if ( $httpCode != 200 ){
        echo "Return code is {$httpCode} \n"
            .curl_error($ch);
            $dosya404 = fopen("404-siteler.txt" , 'a+');
            fwrite ($dosya404 , $line."\n");
            fclose ($dosya404);
    } else {
        echo 'Site: ' .$html_brand."   -Status: ". $httpCode."<br>";
        $dosyatemiz = fopen("temiz-siteler.txt" , 'a+');
        fwrite ($dosyatemiz , $line."\n");
        fclose ($dosyatemiz);
       
    
    
    
    }
    
    
    
    
    curl_close($ch);
    
        }
    }
    
    ?>
  • 27-04-2022, 14:24:50
    #6
    TeknoCoder adlı üyeden alıntı: mesajı görüntüle
    Buyrun hocam umarım çözebilmişimdir
    <?php
    
    $handle = fopen("siteler.txt", "r");
    if ($handle) {
        while (($line = fgets($handle)) !== false) {
    
    $html_brand = trim($line);
    $ch = curl_init();
    
    $options = array(
        CURLOPT_URL            => $html_brand,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER         => true,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_ENCODING       => "",
        CURLOPT_AUTOREFERER    => true,
        CURLOPT_CONNECTTIMEOUT => 120,
        CURLOPT_TIMEOUT        => 120,
        CURLOPT_MAXREDIRS      => 10,
    );
    curl_setopt_array( $ch, $options );
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    
    if ( $httpCode != 200 ){
        echo "Return code is {$httpCode} \n"
            .curl_error($ch);
            $dosya404 = fopen("404-siteler.txt" , 'a+');
            fwrite ($dosya404 , $line."\n");
            fclose ($dosya404);
    } else {
        echo 'Site: ' .$html_brand."   -Status: ". $httpCode."<br>";
        $dosyatemiz = fopen("temiz-siteler.txt" , 'a+');
        fwrite ($dosyatemiz , $line."\n");
        fclose ($dosyatemiz);
      
    
    
    
    }
    
    
    
    
    curl_close($ch);
    
        }
    }
    
    ?>
    Çok teşekkür ederim istediğim oldu.
  • 27-04-2022, 14:53:45
    #7
    burdaki sorun curl in açık kalması mıydı acaba ben onu merak ettim
  • 27-04-2022, 16:34:48
    #8
    omergunay adlı üyeden alıntı: mesajı görüntüle
    burdaki sorun curl in açık kalması mıydı acaba ben onu merak ettim
    Mantık olarak yola çıkışım iyi olsa da, sizin kodlarınıza göre benim kod yapısı bir hayli bozuk benim kodlar. Sorunun nerede olduğunu anlayamasam da bir şeyi iyi anladım. Yarım bıraktığım PHP derslerine tekrar dönmem gerekiyor..