• 23-05-2023, 16:06:04
    #1
    merhaba, file_get_contents($url) ile youtubeden herhangi bir kanaldan veri çekiyorum. fakat bazı kanallar url olarak yönleniyor nadir olarak.
    örneğin:
    $url="https://www.youtube.com/@Vinesbestfun/videos";
    yukardaki url'yi manuel tıklayınca buraya yönleniyor:
    https://www.youtube.com/Vinesbestfun/videos
    dolayısıyla veriyi çekemiyorum. file_get_contents ile Yönlenen url yi nasıl takip edebilirim?
  • 23-05-2023, 16:10:17
    #2
    file_get_contents yerine curl ile istek gönderebilirsin hocam follow_location ile yönlenen urlye geçiş yapabilirsin.
  • 23-05-2023, 16:12:51
    #3
    Bence de curl ile istek gönderip CURLOPT_FOLLOWLOCATION parametresini "true" yapmanız daha kolay olur.

    Örneğin;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "URL ADRESİ");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
    $exec = curl_exec($ch);
    echo $exec;
  • 23-05-2023, 16:13:37
    #4
    <?php
    function getRedirectedURL($url) {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_exec($ch);
        $redirectedURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
        curl_close($ch);
        return $redirectedURL;
    }
    
    // Örnek URL
    $url = "https://www.youtube.com/@Vinesbestfun/videos";
    
    // Yönlendirilmiş URL'yi al
    $redirectedURL = getRedirectedURL($url);
    
    // Yönlendirilmiş URL'yi kullanarak veriyi alabilirsiniz
    $data = file_get_contents($redirectedURL);
    ?>
  • 23-05-2023, 16:14:17
    #5
    Curl ile takip ediyorum fakat file_get_contents ile almam gerekiyor veriyi,
    hallettim. Cevap veren herkese Tşk Ederim. Elinize Sağlık.
  • 23-05-2023, 16:15:08
    #6
    stream_context_create ile birlikte kullanın: https://www.php.net/manual/tr/functi...ext-create.php

    $context = stream_context_create(
        array(
            'http' => array(
                'follow_location' => true
            )
        )
    );
    
    $html = file_get_contents('http://www.youtube.com/@Vinesbestfun/videos', false, $context);
  • 23-05-2023, 16:16:41
    #7
    Yeterli cevaplar verilmişler ben sadece tek bir şey söyleyeceğim eger ki sitede arkayüz degil önyüzden yapılan bir yönlendirme varsa işin zor kolay gelsin