The easiest way is by using the function preg_match_all with Regex
.
Capturing the list through Curl
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://Infinity.quor8.com:8000/get.php?username=USERNAME&password=PASSWORD&type=m3u_plus&output=ts");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Using this code, you will be able to capture all the contents of the file and store in the variable $response
.
It is important that you use options such as CURLOPT_COOKIEJAR
, CURLOPT_COOKIEFILE
, CURLOPT_USERAGENT
etc. Some servers block access when there are no certain headers
.
Filtering the contents of the file
As I mentioned at the beginning, to filter you will need to use regex
.
<?php
preg_match_all('/((?:tvg-name)="(?<name>.*?)".+(?:tvg-logo)="(?<logo>.*?)".+\n(?P<link>https?:?\/\/.+))/', $response, $result, PREG_SET_ORDER);
$data = reset($result);
(?:tvg-name)="(?<name>.*?)"
- Here it will capture all the content involved by the " (quotes) that comes after tvg-name=
.+(?:tvg-logo)="(?<logo>.*?)"
- The .+
is for him to go through all the content until tvg-logo="
and capture the content from between the " (quotes)
.+\n(?P<link>https?:\/\/.+)
- Here the .+
is the same thing as the previous step, the difference is in the \n
which means going through, including, a line break and capturing the entire line that starts with http
or https
The ?:
at the beginning of relatives tells not to capture that term. In this expression it is optional.
Finally, (?<name>.*?)
informs to capture all the value and turn into a group with the name name
This will return you one array
with the data of name, soon and link. Now you can make one foreach
and display the data in a table.
Complete code
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://Infinity.quor8.com:8000/get.php?username=USERNAME&password=PASSWORD&type=m3u_plus&output=ts");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if (substr($info["http_code"], 0, 2) != 20) {
die("Could not connect to server. Check username and password");
}
preg_match_all('/(tvg-name="(?<name>.*?)".+tvg-logo="(?<logo>.*?)".+\n(?P<link>https?:\/\/.+))/', $response, $channels, PREG_SET_ORDER);
?>
<table>
<thead>
<tr>
<th>Logo</th>
<th>Name</th>
<th>Link</th>
</tr>
</thead>
<tbody>
<?php foreach($channels as $channel): ?>
<tr>
<td><img src="<?php echo $channel["logo"] ?>" height="75" width="75" /></td>
<td><?php echo $channel["name"] ?></td>
<td><?php echo str_replace(".ts", ".m3u8", $channel["link"]) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
You can also customize with css
:
<style>
.channel {
float:left;
}
</style>
<div id="channels">
<?php foreach($channels as $channel): ?>
<div class="channel">
<a href="<?php echo str_replace(".ts", ".m3u8", $channel["link"]) ?>" title="<?php echo $channel["name"] ?>">
<img src="<?php echo $channel["logo"] ?>" height="75" width="75" alt="<?php echo $channel["name"] ?>" />
</a>
</div>
<?php endforeach; ?>
</div>
If you want to replace a value while adding the data in the table, just use preg_replace
or str_replace
.
I think it’s never a good idea to pass Users and Passwords by
GET
....– Matheus Cuba
@Matheuscuba the biggest problem is passing http instead of https. Without https, both POST and GET pass the open passwords. The POST only seems a little more discreet, but the difference is not as much as the people think. GET only gets a little worse because of the history, but only swap for POST is not real solution.
– Bacco
Right, but in this case I just need to list in table form the data I put up there, I will not pass the user data but upload the data I need that are in the file of that url
– André Luiz Mardonis
@Bacco I fully agree with you, but still requests
POST
despite being as exposed as requisitionsGET
, are still little, more secure. It is not all Users who possess the knowledge necessary to intercept their data. It is extremely necessary to use SSL certificate for security, but leave a login request with GET? Any Corner User can copy the URL and exit using– Matheus Cuba
I know, Metheus, but I don’t think you understand the point. It does not matter if you will have login and Sneha in the url, what need is to get the data from the file that this url low.
– André Luiz Mardonis