I have a php script that will return a google search but it gives me the HTTP error.
if (strstr(file_get_contents("http://www.google.com/search?q=site:http://". $url ."&gws_rd=ssl"), 'did not match any documents.'))
{
return "No";
}
else {
return "Yes";
}
A PHP Error was encountered
Severity: Warning
Message: file_get_contents(http://www.google.com/search?q=site:http://google.com&gws_rd=ssl): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
Filename: libraries/google_index.php
Line Number: 8
error : HTTP request failed! HTTP/1.0 503 Service Unavailable.
how can i force this or something so it will get the contents.
If you put an URL as GET parameter of another URL, you must urlencode() it. Otherwise, some characters like ? or & will be considered as parts of the main URL.
Try encoding the whole URL, like:
$string = "google.com/search?q=site:". urlencode($url ."&gws_rd=ssl")
Related
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 am using PHP Simple HTML DOM Parser to get a data from a website. I call this following function in a while loop say for example 15 actors data to be scraped. what happens is after scraping data for 5 or 6 or somewhere in loop, it fails to open the stream and breaks the script. I used try and catch function. but still i am not to fix it out. Actually my need is even if it fails in the middle of a loop, it has to go on till the end. Can anyone assit me pls.
function get_data($actor) {
try {
$html = file_get_html('http://someurl.com', false, $context);
if (isset($html)) {
$table1 =$html->find('table.table_border',0) ;
// doing some process here
}
} catch(Exception $e) {
echo $tt_id."-Failed once.<br>";
}
}
Sometimes i am getting the following error and the script stops.
Warning: file_get_contents(http://someurl.com) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable
Fatal error: Call to a member function find() on a non-object in somefile.php on line 37
I would like to Reverse Geocoding (from GPS coordinates to addresses) and I have a http request from Google Api and is :
$StringaCo= file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng='. $x . ', '.$y.'&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk');
and I process this http request with :
$StringL= json_decode($StringaCo);
now I want to print all with :
print_r($StringL);
but I received this error :
Warning : file_get_contents(https://maps.googleapis.com/maps/api/geocode/json?latlng=41.805931099999995, 12.432546499999999&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request.
Could someone, please, help me?
change:
$StringaCo= file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng='.$x.', '.$y.'&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk');
to:
$StringaCo= file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng='. $x.','.$y.'&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk');
you need remove extra space after comma
I'm using the following line with to get the page content:
$handle = file_get_contents(
"http://www.mywebsite.com/index.php?show=users&action=msg§ion=send",
NULL,
NULL,
1000,
19000);
And then, I'm getting the following message:
Warning:
file_get_contents(http://www.mywebsite.com/index.php?show=users&action=msg §ion=send):
failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
(Please take a note at the bolded part).
What happened to it? Why does it changes the url param?
I don't think PHP is changing querystring parameters.
If you are reading that message in the browser, it should be just a matter of how the output is HTML formatted. So, the 403 error you are getting it should not be related to some unwanted url transformation.
function modify(.......)
{
$mcontact = file_get_contents( "https://test.httpapi.com/api/contacts/modify.json?auth-userid=$uid&auth-password=$pass&contact-id=$cid&name=$name &company=$company&email=$email&address-line-1=$street&city=$city&country=$country&zipcode=$pincode&phone-cc=$countryCodeList[$phc]&phone=$phone" );
$mdetails = json_decode( $mcontact, true );
return $mdetails;
}
using this modify function, displays warning mesage
Warning: file_get_contents(https://...#hihfg.com&address-line-1=3,dfgdf,fgdf&city=dfgfd&country=India&zipcode=641005&phone-cc=91&phone=756657)
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.0 400 Bad request in /home/gfdgfd/public_html/new_one/customer/account/class.whois.php
on line 49
Please help me, modify contact details..
HTTP/1.0 400 Bad request - everything you need to know: You are sending a request the server doesn't like.
Are you sure it accepts a GET request and doesn't require POST? Is the URL correct?
Your URL is wrong. You have an additional space character: &name=$name &company=$company. Remove it.