oracle765 Posted April 22, 2015 Share Posted April 22, 2015 ERROR MESSAGE IS Warning: simplexml_load_file(http://www.geoplugin.net/xml.gp?ip=180.92.194.149): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/public_html/hotel_list.php on line 151 Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://www.geoplugin.net/xml.gp?ip=180.92.194.149" in /home/public_html/hotel_list.php on line 151 OUR CODE FOR THIS IS // Ip track $ip=$_SERVER['REMOTE_ADDR']; $xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".$ip); $ip_curency = (string)$xml->geoplugin_currencyCode ; We have had some code written to search for a hotel for quite some time and are receiving HTTP request failed errors and I cannot figure out what is wrong The error and code is as follows Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/ Share on other sites More sharing options...
Muddy_Funster Posted April 22, 2015 Share Posted April 22, 2015 ...HTTP request failed! HTTP/1.1 403 Forbidden Makes me think that you (or more specifically your script) are not authorised to access that page. Make sure the permissions are set right on the target. Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1509608 Share on other sites More sharing options...
oracle765 Posted April 22, 2015 Author Share Posted April 22, 2015 hi Muddy_Funster You have totally lost me with that function lol, what do I need to do with that function? and also do you mean I am not allowed to access that geoplugin site thanks Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1509612 Share on other sites More sharing options...
joel24 Posted April 22, 2015 Share Posted April 22, 2015 (edited) the function you're referring to is in Muddy_Funster's signature, not directed at this topic. as Muddy said, you're not authorised to access that page. Geoplugin has a usage limit for free access - i've tested your code and it's working fine from my IP. are you running this code on your local machine or a web server? Edited April 22, 2015 by joel24 Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1509615 Share on other sites More sharing options...
oracle765 Posted April 23, 2015 Author Share Posted April 23, 2015 hi there I am running this from our webserver Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1509708 Share on other sites More sharing options...
joel24 Posted April 23, 2015 Share Posted April 23, 2015 is it a shared webserver? I attempted loading the geoplugin from my local host and repeated a large number of times and now i'm getting a 403 forbidden also. You'll need to either buy a licence for geoplugin as if you're on a shared host, any other users on the same box will have the same IP address and if they happen to be using geoplugin it will impact on your usage... though you'll want to get a unique IP address also, otherwise you buying a licence will entail that other users on your shared host will be able to use your licence. Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1509719 Share on other sites More sharing options...
oracle765 Posted April 28, 2015 Author Share Posted April 28, 2015 <?php session_start(); require_once('config/config.php'); require_once('flight_form_check.php'); require_once('funtion.php'); //ini_set('display_errors', 1); //error_reporting(E_ALL); unset($_SESSION['page']); unset($_SESSION['Search_data']); unset($_SESSION['class']); unset($_SESSION['audult']); unset($_SESSION['child']); unset($_SESSION['infent']); unset($_SESSION['startdate']); unset($_SESSION['enddate']); unset($_SESSION['user_currency']); unset($_SESSION['Places']); unset($_SESSION['Carriers']); unset($_SESSION['Agents']); unset($_SESSION['stop_filter']); unset($_SESSION['Airline']); $originplace = $_GET['strtplace']; $destination = $_GET['endplace']; $start_date = $_GET['startdate']; if(isset($_GET['enddate']) && $_GET['enddate']!=""){ $end_date = $_GET['enddate'];} $audult = $_GET['audult']; if(isset($_GET['child']) && $_GET['child']!=""){ $child = $_GET['child'];} if(isset($_GET['infent']) && $_GET['infent']!=""){ $infent = $_GET['infent'];} $class = $_GET['class']; if($originplace == $_SESSION['Form'] && $destination == $_SESSION['To'] && $start_date == $_SESSION['S_date'] & $end_date == $_SESSION['E_date'] && $audult == $_SESSION['Adult'] & $class == $_SESSION['Class']) { $SessionKey = $_SESSION['Key']; $query = ""; if($_GET['stops']!="") { if($_GET['stops'] == 5){$stop = 0;} else {$stop = $_GET['stops'];} $query .="&stops=".$stop; } if($_GET['duration']!="") { $duration = $_GET['duration']*60 ; $query .= "&duration=".$duration ; } if($_GET['sort']!="") { $query .="&sorttype=".$_GET['sort']; $query .="&sortorder=asc"; } if($_GET['pageindex'] == ""){$_GET['pageindex'] = 0 ;} //$query .="&pageindex=".$_GET['pageindex']; //$query .="&pagesize=1000"; $array = PollSession($SessionKey,$query); } else { $ip = $_SERVER['REMOTE_ADDR']; $xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".$ip); $ip_curency = (string)$xml->geoplugin_currencyCode ; $ip_country = (string)$xml->geoplugin_countryCode ; if($ip_curency == "") { $ip_curency = "AUD";} if($ip_country == "") { $ip_country = "AU";} $query = "&country=".$ip_country; $query .= "¤cy=".$ip_curency; $query .= "&locale=en-".$ip_country; $query .= "&originplace=".$originplace; $query .= "&destinationplace=".$destination; $query .= "&outbounddate=".$start_date; if(isset($end_date) && $end_date!=""){ $query .= "&inbounddate=".$end_date;} //$query .= "&adults=1"; $query .= "&adults=".$audult; $query .= "&groupPricing=true"; if(isset($child) && $child!=""){ $query .= "&children=".$child;} if(isset($infent) && $infent!=""){ $query .= "&infants=".$infent;} $query .="&locationschema=Sky"; $query .="&cabinclass=".$class; //$apiParamsUrl = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/".$SessionKey."/booking?apikey=SECRET"; $apiParamsUrl = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0?apikey=SECRET".$query.""; $apiParamsStr = parse_url($apiParamsUrl, PHP_URL_QUERY); parse_str($apiParamsStr, $apiParamsArray); $apiSessionUrl = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0'; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $apiSessionUrl); curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json')); curl_setopt($ch,CURLOPT_POST, count($apiParamsArray)); curl_setopt($ch,CURLOPT_POSTFIELDS, $apiParamsStr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_HEADER, 1); $response = curl_exec($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); curl_close($ch); preg_match('~Location: ([^\s]+)~', $header, $matches); $apiSessionUrl = $matches[1]; $apiSessionUrl .= '?apiKey=' . $apiParamsArray['apikey']; @$data = file_get_contents($apiSessionUrl); $arra = json_decode($data, true); $_SESSION['Form'] = $originplace; $_SESSION['Class'] = $class; $_SESSION['To'] = $destination; $_SESSION['S_date'] = $start_date; $_SESSION['E_date'] = $_GET['enddate']; $_SESSION['Adult'] = $audult; $_SESSION['Key'] = $arra['SessionKey']; $_SESSION['page'] = 0 ; $SessionKey = $arra['SessionKey']; $query = ""; //$query .="&pageindex=".$_GET['pageindex']; //$query .="&pagesize=1000"; //$query = "&adults=".$audult; //PollSession($SessionKey,$query); PollSession($SessionKey,$query); PollSession($SessionKey,$query); sleep(; $array = PollSession($SessionKey,$query); } $k=0; //echo"<pre>"; //print_r($array); //die(); function search($array, $key, $value) { $results = array(); if (is_array($array)) { if (isset($array[$key]) && $array[$key] == $value) { $results[] = $array; } foreach ($array as $subarray) { $results = array_merge($results, search($subarray, $key, $value)); } } return $results; } ?> yes it is a shared host, I understand what you mean. I am just curious if I could be looping through the and calling it more than once but I do not fully understand the code, please find attached the part of my page code. Can you notice anything? Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1510148 Share on other sites More sharing options...
joel24 Posted April 28, 2015 Share Posted April 28, 2015 what is your pollsession function? it's calling another api so shouldn't be initiating another request to geoplugin. Could you show us the pollsession() function and also put the following line on your script after $xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".$ip); // put after the above line which is already in your code $_SESSION['geoplugin']=(isset($_SESSION['geoplugin'])) ? $_SESSION['geoplugin']+1 : 1; echo "<p>Calling geoplugin {$_SESSION['geoplugin']} times</p>"; Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1510161 Share on other sites More sharing options...
oracle765 Posted April 29, 2015 Author Share Posted April 29, 2015 function PollSession($sessionkey,$query) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); curl_setopt($ch, CURLOPT_URL,'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/'.$sessionkey.'?apiKey=SECRET'.$query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); $re = explode("SessionKey",$data); $response = '{"SessionKey'.$re[1]; $array = json_decode($response, true); return $array; } Warning: simplexml_load_file(http://www.geoplugin.net/xml.gp?ip=1.121.148.196): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/oracle765/public_html/flight_results.php on line 69 Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://www.geoplugin.net/xml.gp?ip=1.121.148.196" in /home/oracle765/public_html/flight_results.php on line 69 Calling geoplugin 1 times hi There I have put that echo in and it says it is only calling 1 times and please find the pollsession you requested Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1510259 Share on other sites More sharing options...
joel24 Posted April 29, 2015 Share Posted April 29, 2015 well if it's only calling it once and you're receiving a 403, either you've been manually blocked or the IP of your shared host has hit it too many times. Can you run that script successfully from another IP? i.e. your local machine? that way you can debug - or contact geoplugin enquiring as to why you're receiving the 403 from your IP. Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1510277 Share on other sites More sharing options...
oracle765 Posted April 30, 2015 Author Share Posted April 30, 2015 ok great that's sounds like whats wrong, they have said it blocks for 1 hour when there are too many requests that is my ip and it works fine at the moment, so there must be something else hitting it, I will check with them Thanks for all the help Quote Link to comment https://forums.phpfreaks.com/topic/295747-http-request-failed/#findComment-1510397 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.