PHP code for weather info of the visitor -


<?php require_once('geoplugin.class.php'); $geoplugin = new geoplugin(); // if wanted change base currency, uncomment following line // $geoplugin->currency = 'eur';  $geoplugin->locate(); echo "<p </span></p> </br>";  echo "<p style='text-align: center;'><span style='font-size: 50px; font-family: georgia,palatino; color: #202020 ;'> ip address {$geoplugin->ip} </span></p> </br>";  echo "<p style='text-align: center;'><span style='font-size: 16px; font-weight: bold; text-decoration: underline; font-family: georgia,palatino; color: #d67900;'> more information </span></p>";  echo "<p style='text-align: center;'><span style='font-size: 13px; font-family: georgia,palatino; color: #686868;'> country: {$geoplugin->countryname} | city: {$geoplugin->city} | country code: {$geoplugin->countrycode} | longitudes: {$geoplugin->longitude} | latitude: {$geoplugin->latitude} | currency code: {$geoplugin->currencycode} | currency symbol: {$geoplugin->currencysymbol} </span>";  ?> 

i have above code give me ip address along city , county of visitor. need find weather condition of city this.

here "{$geoplugin->city}" giving me city info.

you'd need weather api. check out this one, api docs available here

a php example using curl:

<?php     $city = "london"; //assign city     $apikey = "42esgfa4pfqp6zwgr4egjbph"; //assign api key         $weatherrequest = curl_init(); //make new curl request         curl_setopt_array($weatherrequest, array(             curlopt_returntransfer => 1,             curlopt_url => "http://api.worldweatheronline.com/free/v1/weather.ashx?q=".$city."&format=json&num_of_days=5&key=".$         ));         $response = curl_exec($weatherrequest); // execute curl request , reponse         curl_close($weatherrequest); // close request after have received response         $json = json_decode($response, true);         //if using celsius:         echo($json["data"]["current_condition"]["temp_c"]);         //if using fahrenheit:         //echo($json["data"]["current_condition"]["temp_f"]); ?> 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -