I have a problem with my website. My website gets a variable and returns a String. What I mean by that is that if you visit my website the code will me only a 3 digit String eg FEG, PSJ, FGT, HJK. I want to take this String using the file_get_contents function. But when I do $con = file_get_contents("http://website.com/test.php?name=George"); it gives me this error
Warning: file_get_contents("http://website.com/test.php?name=George"): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in C:\xampp\htdocs\test.php on line 2
Example using cURL instead:
<?php
$ch = curl_init("http://website.com/test.php?name=George");
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
Related
I have a script that grabs the duration of a Youtube video.
It was working fine but for some reason it now gets the following error:
Warning:
file_get_contents(https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=Prt-G4cPIn4&key=[API_KEY]):
failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
Here's the code:
$dur = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=$video_id&key=$apikey");
$duration = json_decode($dur, true);
foreach ($duration['items'] as $vidTime) {
$vTime = new DateInterval($vidTime['contentDetails']['duration']);
}
$vid_time = $vTime->format('%H:%I:%S');
I have no idea why this would stop working all of a sudden.
The var $apikey is wrong "[API_KEY]", solve this first and go appear other error, comming by the headers and CORS
I am trying to create a simple script with file_get_contents and Facebook graph. However, there seems to be some issue with the error handling.
Here is the code I have:
$json = file_get_contents('https://graph.facebook.com/', true);
if($json !== FALSE) {
echo "test";
}
It returns the following error message:
Warning: file_get_contents(https://graph.facebook.com/): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/test/tst/mellemmand/test.php on line 4
I'm trying to scrape data from some websites. For several sites it all seems to go fine, but for one website it doesn't seem to be able to get any HTML. This is my code:
<?php include_once('simple_html_dom.php');
$html = file_get_html('https://www.magiccardmarket.eu/?mainPage=showSearchResult&searchFor=' . $_POST['data']);
echo $html; ?>
I'm using ajax to fetch the data. When I log the returned value in my js it's completely empty.
Could it be due to the fact that this website is running on https? And if so, is there any way to work around it? (I've tried changed the url to http, but I get the same result)
Update:
If I var_dump the $html variable, I get bool(false).
My PHP error log says this:
[27-Feb-2014 22:20:50 Europe/Amsterdam] PHP Warning: file_get_contents(http://www.magiccardmarket.eu/?mainPage=showSearchResult&searchFor=tarmogoyf): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
in /Users/leondewit/PhpstormProjects/Magic/stores/simple_html_dom.php on line 75
It's your user agent, file_get_contents doesn't send one by default, so:
$url = 'http://www.magiccardmarket.eu/?mainPage=showSearchResult&searchFor=tarmogoyf';
$context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla compatible')));
$response = file_get_contents($url, false, $context);
$html = str_get_html($response);
echo $html;
I am trying to invoke http://dbpedia.org/page/Los_Angeles in PHP with HTTP headers for an educational assignment I have been given. It must be this URL i.e. I am not allowed to use the JSON URL directly.
<?php
// Create a stream
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Accept: application/json"
)
);
$context = stream_context_create($opts);
$url = "http://dbpedia.org/page/Los_Angeles";
$data = file_get_contents($url,false,$context);
echo $data;
?>
I'm facing this error:
Warning: file_get_contents(http://dbpedia.org/page/Los_Angeles): failed to open stream: HTTP request failed! HTTP/1.1 406 Unacceptable.
Please help to get rid of this error. Note: I read about this error and found suggestions to use CURL. However, I don't want to go into installation of CURL. Kindly suggest using file_get_contents.
406 says that application/json is not available.
From Wikipedia:
406 Not Acceptable The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.
<?php
$url = "http://dbpedia.org/page/Los_Angeles";
$data = file_get_contents($url);
echo $data;
?>
I am having a problem with PHP's file_get_contents command.
$url = "http://api.rememberthemilk.com/services/rest/".$format.$auth_token.$filter."&api_sig=".$md5.$apikey.$method;
$content = file_get_contents($url);
$array = json_decode($content, true);
$taskname = $array['rsp']['tasks']['list']['taskseries']['name'];
$duedate = $array['rsp']['tasks']['list']['taskseries']['task']['due'];
($format, $auth_token, $filter, $md5, $apikey, $method are already defined in the script)
When I try to run this code this error is returned:
[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad request for line 101
line 101 = $content, = file_get_contents($url);
How to fix this? Thanks!!!
This url does not look great.
http://api.rememberthemilk.com/services/rest/?format=json&auth_token=AUTH_TOKEN&filter=dueWithin:"3 days of today"&api_sig=API_SIG&api_key=API_KEY&method=rtm.tasks.getList
Encode the tokens as follows:
$filter = 'filter='.urlencode( 'dueWithin:"3 days of today"' );
Use urlencode().
Try printing the URL after concatenating the variables. Then paste the URL into the address bar of your browser and see what comes back. Because it's a web service call, your browser might not know what to do with the response. In that case you might get additional information using the command-line user agent "curl", e.g.
curl -v 'http://some-url'
curl is built in to Macs and other *nix machines and is also available for Windows.