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

8
  • 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. Commented Mar 6, 2021 at 22:46
  • Does this answer your question? Is there any way to echo '&timestamp' in php? Commented Mar 6, 2021 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. Commented Mar 7, 2021 at 1: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 . Commented Mar 7, 2021 at 10:07
  • 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). Commented Mar 8, 2021 at 16:36

1 Answer 1

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 ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.