1

Hi,

i have this code php

$url = "http://dikoiptv.zapto.org:25461/get.php?username=202020212022&password=303202404&type=m3u_plus&output=hls" ; 
if(isset($url)) {
  $m3ufile = file_get_contents($url);
echo $m3ufile ;
}

When I call the page the code does not work and this error appears in the file of error_log

[06-Mar-2021 18:52:45 UTC] PHP Warning:  file_get_contents(http://dikoiptv.zapto.org:25461/get.php?username=202020212022&password=303202404&type=m3u_plus&output=hls): failed to open stream: Connection refused in /home/wwww/public_html/video/index.php on line 4

The problem with replacing this & in the link to & amp; Is there a solution to this problem, thank you

i get no error message, just blank page, and the code works fine on the ionos hosting. I encounter this problem with other platforms enter image description here

  • When you add `header("Content-Type: text/plain"); var_dump($url);` after you have assigned the variable `$url`, what is the output you get? Please [edit] your question to include the output you get with the changed PHP code. – Progman Mar 06 '21 at 22:46
  • Does this answer your question? [Is there any way to echo '&timestamp' in php?](https://stackoverflow.com/questions/66254741/is-there-any-way-to-echo-timestamp-in-php) – steven7mwesigwa Mar 06 '21 at 22:48
  • The error message seems unrelated to the "&" in the URL. You're getting a "connection refused" warning. In other words, PHP is unable to connect to the server, perhaps due to a firewall issue or because there's nothing listening on port 25461. – rickdenhaan Mar 07 '21 at 01:45
  • The link I put in the $url is a working link, but the link it came back to cannot be connected because contains an error if you notice the difference between them you can see that it has changed the symbol & with this symbol "&" And that's where the problem . – MR ACHRAF DZ Mar 07 '21 at 10:07
  • @MRACHRAFDZ That the `&` gets replaced by `&` while logging the warning might be unrelated to the problem of reaching the external server. What error message do you get when you only use the URL `http://dikoiptv.zapto.org:25461/get.php?username=202020212022`? Please [edit] your question to include the result or error message when you use this URL, which does not have any `&` in it. – Progman Mar 07 '21 at 10:21
  • i d'ont grt on error message, just blank page, and the code works fine on the ionos hosting. I encounter this problem with other platforms – MR ACHRAF DZ Mar 07 '21 at 10:45
  • @MRACHRAFDZ When you use the URL `http://dikoiptv.zapto.org:25461/get.php?username=202020212022`, do you get any warnings in your PHP script execution or in your log file? If yes, what are these errors/warnings? If not, what is the content of the `$m3ufile` variable? Please [edit] your question to include these new information and make it clear where you use which URL on which host, as it seems you have multiple hosts available? Make it clear which one is problematic and which one is working. – Progman Mar 07 '21 at 11:14
  • 2
    It's quite possible that GoDaddy has the `allow_url_fopen` directive disabled. Can you run `phpinfo()` and check? If that's the case, you cannot use `file_get_contents()` to load a remote URL but only to load local files and you'd have to use something else such as cURL, as suggested by @steven7mwesigwa). – rickdenhaan Mar 08 '21 at 16:36

1 Answers1

2

From the looks of it, there is absolutely nothing wrong with your source code.
At least, it returns the expected result on my local machine just fine.
I believe it has little to do with file_get_contents(...) or the $url.

For some unknown reason, other platforms (i.e. GODADDY HOSTING ) seem to convert & characters into & in your URL before it gets passed to file_get_contents($url)

Hence:

$m3ufile = file_get_contents("http://dikoiptv.zapto.org:25461/get.php?username=202020212022&password=303202404&type=m3u_plus&output=hls");

would throw a 401 Unauthorized error:

PHP Warning:  file_get_contents(http://dikoiptv.zapto.org:25461/get.php?username=202020212022&password=303202404&type=m3u_plus&output=hls): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

One alternative would be to try using cURL instead to see if that resolves the issue.

$params = [
    "username" => "202020212022",
    "password" => "303202404",
    "type" => "m3u_plus",
    "output" => "hls"
];

$url =  "http://dikoiptv.zapto.org:25461/get.php?". http_build_query($params);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$m3ufile = curl_exec($ch);
curl_close($ch);

echo $m3ufile ;
steven7mwesigwa
  • 5,701
  • 3
  • 20
  • 34