PHP XML Feed访问呈现URL文件访问被禁用

时间:2011-09-13 11:19:50

标签: php xml

我一直在将自己的网站从wordpress移到自己的平台上。暂时我想使用在wordpress端的PHP文件中加载的XML提要从谷歌访问maps api。从新平台的离线测试页面访问此内容即可呈现。

  

在服务器配置中禁用了URL文件访问

以下页面应该从XML Feed中呈现路线。亲自试试吧。 http://www.golfbrowser.com/wp-content/themes/light/utilities/directions.php?start=RG426ly&end=SL42ES

PHP看起来像这样,

<?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 = (string)$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;


?>

为什么现在这样做?

非凡

1 个答案:

答案 0 :(得分:0)

在php.ini中,您需要具有以下配置:

  

allow_url_fopen =开;   allow_url_include =开;

请注意,这会使您的网站容易受到XSS攻击,并且建议不要在生产服务器上使用。