I want to create weather informer that shows weather forecast by visitor's IP.
I'm trying to place variable $ip to the URL but it doesn't work. When I place real IP instead of .$ip. it works.
What am I doing wrong?
$ip=$_SERVER['REMOTE_ADDR'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://free.worldweatheronline.com/feed/weather.ashx?key=xxxxxxxxxxxxxxx&q=.$ip.&localObsTime&num_of_days=5&format=json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$outputJson = curl_exec($ch);
if ($outputJson === FALSE) {
echo 'Error: '.curl_error($ch);
}
echo '<pre> ';
print_r($outputJson);
echo '</pre> ';