Problem with php code when using & symbol in the link
Get the solution ↓↓↓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
Answer
Solution:
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 withfile_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 tofile_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 a401 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 ;
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: xml parsing error: no root element found
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.