I want to use the contents of a website and include them in mine with "Simple Html DOM", unfortunately the code which normally works for another websites, fails in this specific case:
<?php
// Note you must download the php files from the link above
// and link to them on this line below.
include_once('simple_html_dom.php');
$html = file_get_html('http://www.comelmar.it/index.aspx?idmnu=23&midx=3&mbidx=2&idmnub=8&Lang=EN');
$elem = $html->find('table[class=Descrizione]', 0);
echo $elem;
?>
Warning:
file_get_contents(http://www.comelmar.it/index.aspx?idmnu=23&midx=3&mbidx=2&idmnub=8&Lang=EN)
[function.file-get-contents]: failed to open stream: HTTP request
failed! HTTP/1.1 500 Internal Server Error in
public_html/elin-custom-code/simple_html_dom.php on
line 75
Fatal error: Call to a member function find() on a non-object in
public_html/elin-custom-code/sklad-1.php on line 9
As a link for the reference:-
file_get_contents - failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
Most hosting provides now block the furl_open parameter which allows you to use file_get_contents() to load data from an external url.
You can use CURL or a PHP client library like Guzzle.
To be make sure i just use CURL to check what is the exact problem with the help of below code:-
<?php
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://www.comelmar.it/index.aspx?idmnu=23&midx=3&mbidx=2&idmnub=8&Lang=EN');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
echo "<pre/>";print_r($query);
?>
Output:- http://prntscr.com/a91nl5
So it seems that for security reason these method calls(CURL and file_get_contents) are blocked on that site.
You can try this link answers also, may be you will get some useful output:-
PHP file_get_contents() returns "failed to open stream: HTTP request failed!"
Good Luck.
Related
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
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 ;
I am trying to use the Steam API but whenever I use a file_get_contents() with the Steam Community URL I get this error:
Warning: file_get_contents(http://steamcommunity.com/market/priceoverview/?currency=1&appid=578080&market_hash_name=Gas%20Mask): failed to open stream: HTTP request failed! HTTP/1.0 429
If I use file_get_contents() on Google.com, for example, it returns the page without an error. I have tried to use curl which just returns random characters. Here is the code I used:
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "http://steamcommunity.com/market/priceoverview/?currency=1&appid=578080&market_hash_name=Gas%20Mask");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
echo $output;
Result:
��+��O��%
My domain was temporarily banned from making requests to the URL. I tested the code on another server and it worked.
I already googled and searched for an answer, and found also one, but I still get an error...
I just want to start a cronjob by calling a certain URL but I get this failure message:
PHP Warning: fopen(https://my-url.de): failed to open stream: HTTP request failed! in /var/www/vhosts/httpdocs/cronjob/import.php on line 41
I tried this one:
ignore_user_abort(true);
set_time_limit(0);
But it is not working... The url triggers a cronjob but this one needs to long to response...
So what would you suggest to call a cronjob in PHP?
I must call the cronjob by URL and I do not need to get a response!
Greetings and Thank You!
you can use curl instead of fopen as follows
$url = 'https://my-url.de';
$ch = curl_init($url);
// this will prevent printing out the contents , unless you are make echo $content
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
For now i'm testing using file_get_content(url), but it's returning an error.
The request and response are in the same server:
warning: file_get_contents(https://192.168.1.15/adverts/locations): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in xxxxx
The Web-service returns a json object, so the function file_get_contents will receive a json.
I want to use cURL approach, but it doesn't work too.
So i thought to start ,fix this error first and get contents, and after try to debug why cURL is not working, since i'm getting content with this function
{"status":"success","alerts":[],"content":{"types":[{"id":"P","description":"Permanent"},{"id":"C","description":"Contract"}]}}
Try this with your webservice url and tell us if it throws some kind of Exception :
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "192.168.1.15/adverts/locations");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
Are you sure you can use HTTPS with your server ? Have you the right settings and certificates ?
I'm trying to use this code in a php file.
I want get the source code from this url and parse the content.
<?php
$fuente = file_get_contents('http://www.akiracomics.com');
echo $fuente;
?>
The problem is, after execute the code I received this error
Warning: file_get_contents(http://www.akiracomics.com) [function.file-get-contents]: failed to open stream: Connection timed out in XXXXXX/test.php on line 2
I tried from the same server to other url and works perfect.
Any idea?
Thanx
It's working here, probably you're making too many requests (what are you trying to do, by the way?) and they are blocking incoming requests from your server.
I finally found the solution. I need to use a curl_exec instead file_get_contents.
With this code, everything works fine.
$curlIMG = curl_init();
curl_setopt($curlIMG, CURLOPT_URL, "http://www.google.es");
curl_setopt($curlIMG, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlIMG, CURLOPT_HEADER, false);
$imgBinary = curl_exec($curlIMG);
curl_close($curlIMG);