PHP XML Feed access rendering URL file-access is disabled
I have been removing our website from wordpress onto its own platform. Temporarily I wanted to access the maps api from google using an XML feed loaded in a PHP file on the wordpress side. Accessing this from the offline testing page of the new platform is rendering.
URL file-access is disabled in the server configuration
The following page should instead render directions from the XML feed. Try it for yourself. http://www.golfbrowser.com/wp-content/themes/light/utilities/directions.php?start=RG426ly&end=SL42ES
The PHP looks like this,
<?php
$start = $_POST['start'];
$end = $_POST['end'];
$xml = simplexml_load_file('http://maps.googleapis.com/maps/api/directions/xml?origin='.$start.'&destination='.$end.'&sensor=false');
// data to fetch
$startlat = $xml->xpath("/DirectionsResponse/route/leg/start_location/lat");
$startlng = $xml->xpath("/DirectionsResponse/route/leg/start_location/lng");
$endlat = $xml->xpath("/DirectionsResponse/route/leg/end_location/lat");
$endlng = $xml->xpath("/DirectionsResponse/route/leg/end_location/lng");
$start = $xml->xpath("/DirectionsResponse/route/leg/start_address");
$end = $xml->xpath("/DirectionsResponse/route/leg/end_address");
$start = (string)$start[0];
$end = (string)$end[0];
$startlat = (string)$startlat[0];
$startlng = (string)$startlng[0];
$endlat = (string)$endlat[0];
$endlng = (string)$endlng[0];
// Route Information
$distance = $xml->xpath("/DirectionsResponse/route/leg/distance/value");
$duration = $xml->xpath("/DirectionsResponse/route/leg/duration/value");
$distance = (开发者_如何学Gostring)$distance[0];
$duration = (string)$duration[0];
$duration = round(($duration / 60), 0);
if ($duration > 60)
{
$hours = round(($duration / 60),0). ' hour and ';
$minutes = $duration % 60 . ' minutes';
}
if ($duration == 60)
{
$hours = round(($duration / 60),0). ' hour';
$minutes == '';
}
if ($duration >= 120)
{
$hours = round(($duration / 60),0). ' hours and ';
$minutes = $duration % 60 . ' minutes';
}
if ($duration < 60)
{
$minutes = $duration % 60 . ' minutes';
}
$distancekm = round(($distance * 0.001), 1);
$distancem = round(($distance * 0.000621371192), 1);
// Directions
$directions = $xml->xpath("/DirectionsResponse/route/leg/step");
// Compilation
$outputo = '
<li class="dirtotal"><b>Route Overview</b><br>'.$distancem.' miles ('.$distancekm.' km) <br />about '.$hours.' '.$minutes.'</li>';
$outputs = '<li class="dirstart" value="'.$endlat.', '.$endlng.'"><b>'.$start.'</b></li>';
$output = '';
$distancem = '';
$distancekm = '';
$duration = '';
$order = 0;
foreach ($directions as $direct) {
$latitude = $direct->start_location->lat;
$longitude = $direct->start_location->lng;
$output .= '<li class="dir" value="'.$endlat.', '.$endlng.'"><span class="tit">'. $order += 1 .'</span>';
if($distancekm != '') {
$latlong = $latitude.', '.$longitude;
$output .= '<div>Drive '.$distancem.' miles ('.$distancekm.' km) then';
}
else {
$output .= '<div>';
}
$instructions = $direct->html_instructions;
$duration = $direct->duration->value;
$distance = $direct->distance->value;
$distancekm = round(($distance * 0.001), 1);
$distancem = round(($distance * 0.000621371192), 1);
$output .= '<b>'.$instructions.'</b></div><span class="end"></span></li>';
}
$outpute =
'<li class="dirend" value="'.$endlat.', '.$endlng.'"><b>'.$end.'</b></li>';
// output
$outputs = $outputo.$outputs.$output.$outpute;
echo $outputs;
?>
Any ideas why its doing this now?
Marvellous
In php.ini you need to have the following configuration:
allow_url_fopen = On; allow_url_include = On;
Be aware this makes you site vulnerable for XSS attacks and this isn't recommended to use on production servers.
精彩评论