rendered paste bodyHere is the script:
<?php
define('QUERY_0', 'http://api.hostip.info/get_html.php?ip=');
define('QUERY_1', 'http://www.google.com/ig/api?weather=');
function getWeather() {
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}
$url0 = QUERY_0.$ip;
$ch0 = curl_init();
curl_setopt($ch0, CURLOPT_URL, $url0);
curl_setopt($ch0, CURLOPT_HEADER, 0);
curl_setopt($ch0, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch0, CURLOPT_FAILONERROR, TRUE);
$geo = curl_exec($ch0);
curl_close($ch0);
if( preg_match('/City: (.*)\nIP:/', $geo, $matches) ){
$results = $matches[1];
}else{
$results = 'getLocation failure';
}
$location = urlencode($results);
$url1 = QUERY_1.$location;
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, $url1);
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch1, CURLOPT_FAILONERROR, TRUE);
$weather = curl_exec($ch1);
curl_close($ch1);
$xml = new SimplexmlElement($weather);
echo '<link type="text/css" rel="stylesheet" href="weather.css">';
echo '<div id="weather">';
foreach($xml->weather as $item) {
foreach($item->forecast_information as $new) {
echo '<div class="weatherIcon">';
echo '<center>';
echo '<h3>';
echo $new->city['data'];
echo '</h3>';
echo '<h5>';
echo $new->current_date_time['data'];
echo '</h5>';
echo '</center>';
echo '</div>';
}
foreach($item->current_conditions as $new) {
echo '<div class="weatherIcon">';
echo '<center>';
echo '<img src="http://www.google.com/' .$new->icon['data'] . '"/><br/>';
echo '<h2>';
echo $new->condition['data'];
echo '</h2>';
echo '<h3>';
echo $new->temp_c['data'];
echo '</h3>';
echo '<h5>';
echo $new->humidity['data'];
echo '</h5>';
echo '<h5>';
echo $new->wind_condition['data'];
echo '</h5>';
echo '</center>';
echo '</div>';
}
}
echo '</div>';
}
getWeather();
?>
Here is the CSS:
#weather{
width:140px;
font-size:.8em;
background:#deffcb;
border-width:1px 1px 0 1px;
border-style:solid;
border-color:#ccc;
}
.weatherIcon{
border-bottom:1px solid #ccc;
padding:10px 5px;
overflow:hidden;