How to pick variable from a file from another site by Curl

Asked

Viewed 63 times

0

Good afternoon, you guys. I have a question, like I’m a beginner and I’m using Curl to get some data from a website. I wonder if I can get data from one page to another page because if I am accessing normal error 404.

Example:

I’m on site x: https://site.com/videos/noads.php?video=ProjetoX

On site x, there is an iframe that connects to this link only that I can not access after 404.

But searching for the source, I can find the site and look at the page code..

My question is will I get this Source link?

inserir a descrição da imagem aqui

Thanks in advance, guys. And I’m sorry if I posted it in the wrong place or something.

  • I will not pass because if you do I will put myself in legally punishable position, but if you search the internet have a txt with all these iptv links.

  • I understand your position, just wanted to put in my app, because these public channels falls in 1 day.. But thank you!

1 answer

0

Thus, there are several ways to do this, this is one of them by Curl, however it would not be necessary to do Curl to subtract the parameter:

<?php
class Filter 
{
    public static function getExternalUrl($url_method, $info = false)
    {

    $result = explode('?video=', $url_method, 2);
    $video = (isset($result[1])) ? $result[1] : null;
        try {
            $mime_type = null;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url_method);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            list($mime, $charset) = explode(';', curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
            $result = curl_exec($ch);
           curl_close($ch);
        } catch (Exception $e) {
            $mime = null;
            $charset = null;
            $result = file_get_contents($url_method);
        }
        if ($info) {
            return array('file' => $result, 'mime' => $mime, 'charset' => $charset, 'video' => $video);
        } else {
            return $result;
        }
    }
}
//apenas o retorno sem o vídeo
$data = Filter::getExternalUrl('https://site.com/videos/noads.php?video=ProjetoX');
//resultado completo com vídeo
$data2 = Filter::getExternalUrl('https://site.com/videos/noads.php?video=ProjetoX', true);

print_r([$data, $data2]);
  • Opa, thanks for the reply friend. As reported in the topic I am very beginner, I put the code in my file and ran an error.. Error: https://prnt.sc/10yl4wd Code: https://prnt.sc/10yl6ly To be more exact, the 404 iframe link, as I said but if I access the same in the post print, I can find the value, source = "link" and open. I just wanted to take that amount?

  • In this case, you need to enable cURLno on your apache. It seems that it is disabled, these are examples for php 5 and php 7 if it is linux: sudo apt-get install php7-curl or sudo apt-get install php5-curl, but you can use the function <?php php_info(); ?> and check that it is enabled.

  • Curl should appear as something like that in your php_info.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.