Exemplo n.º 1
0
<?php

require_once "userAuthentication.php";
$SessionID = $_GET['SessionKey'];
$auth = new UserAuth($SessionID);
$SessionResult = $auth->checkUserSession();
if ($SessionResult[0]) {
    $geolocation = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']));
    $APIURL = 'http://www.webservicex.net/globalweather.asmx/GetWeather' . '?CityName=' . urlencode($geolocation['geoplugin_city']) . '&CountryName=' . urlencode($geolocation['geoplugin_countryName']);
    $client = new SoapClient('http://www.webservicex.net/globalweather.asmx?wsdl');
    $params = array("CityName" => $geolocation['geoplugin_city'], "CountryName" => $geolocation['geoplugin_countryName']);
    $xml = $client->GetWeather($params)->GetWeatherResult or die("Cannot get weather results");
    $xml = mb_convert_encoding($xml, "UTF-16", "UTF-8");
    $XMLObject = simplexml_load_string($xml);
    echo json_encode($XMLObject);
    //Invalid XML given by API
    //http://stackoverflow.com/questions/6284548/document-labelled-utf-16-but-has-utf-8-content-in-entity-php-error
    //http://php.net/manual/en/function.mb-convert-encoding.php
    //http://stackoverflow.com/questions/14869227/php-simplexml-parsing-issue
    // $geolocation =  unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=8.8.8.8'));
    //$xml = preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $xml);
    // echo $XMLObject->Location;
} else {
    echo 'Authentication Failed.' . $SessionResult[1];
}
?>