Hi, I've been working on a PHP script which is "supposed" to find an individuals weather based on their geolocation. This script uses "shell_exec".
I have checked my syntax and it is correct, but there is still something missing; for when I call on the script using:
<form action='/weather.php' method='get'><br>
<input type='submit' name='submit' value='Check'><br>
</form>
I get a blank page 🙁
Here is my script:
<?php
function getWeather() {
$ip = $_SERVER['REMOTE_ADDR'];
$geo = shell_exec("/usr/bin/curl -s api.hostip.info/get_html.php?ip=$ip | /usr/bin/sed -e '1d;3d' -e's/C.*: \(.*\)/\1/' -e's|-|%2d|' -e's/ /%20/' -e\s/'/%27/'");
$getAddress = "http://www.google.com/ig/api?weather=$geo";
$xml_str = file_get_contents($getAddress,0);
$xml = new SimplexmlElement($xml_str);
$count = 0;
echo '<div id="weather">';
foreach($xml->weather as $item) {
foreach($item->current_conditions as $new) {
echo '<div class="weatherIcon">';
echo '<img src="http://www.google.com/' .$new->icon['data'] . '"/><br/>';
echo $new->condition['data'];
echo $new->temp_f['data'];
echo $new->temp_c['data'];
echo $new->humidity['data'];
echo $new->wind_condition['data'];
echo '</div>';
}
foreach($item->forecast_conditions as $new) {
echo '<div class="weatherIcon">';
echo '<img src="http://www.google.com/' .$new->icon['data'] . '"/><br/>';
echo $new->day_of_week['data'];
echo $new->condition['data'];
echo $new->low['data'];
echo $new->high['data'];
echo '</div>';
}
}
echo '</div>';
}
getWeather();
?>
I input my command through SSH and it I got positive results:
ST.%20JOHN%27S,%20NL
It did what it was supposed to do, which is take the location and encode the results for URL input.
I'm still not sure as to why I cannot get any output returned when this script is executed in a browser 🙁
I'm a bit of a noob when it comes to this, so any help would be greatly appreciated. Thanks.