Return to Snippet

Revision: 68633
at January 30, 2015 22:37 by Hexahow


Initial Code
//includes the IP2Location framework
require_once('IP2Location.php');

//function that sends and retrieves an answer from a HTTP request
function SendRequest( $url, $method = 'GET', $data = array(), $headers = array('Content-type: application/x-www-form-urlencoded') )
{
	$context = stream_context_create(array
	(
		'http' => array(
			'method' => $method,
			'header' => $headers,
			'content' => http_build_query( $data )
		)
	));

	return file_get_contents($url, false, $context);
}

//the client's IP
$ip = $_SERVER['REMOTE_ADDR'];
// Standard lookup with no cache
$loc = new IP2Location('databases/db24.bin');


$stationCode=FindIPWeatherStationCode($ip,$loc);
GetWeatherForecastFromYahoo($stationCode);

Initial URL
http://www.ip2location.com/tutorials/find-weather-forecast-from-ip-address

Initial Description
To retrieve the weather forecast for your location based only on your current IP, the full tutorial will have the following 5 sections (http://bit.ly/1A5Y651), that will:
- Describe elements needed for weather forecast retrieval
- Describe the weather station code field of IP2Location
- Show code that gets the weather station code from IP address
- Show code that retrieves the weather forecast from Yahoo! Weather using the weather station code.
- Show code that retrieves the weather forecast using IP2Location

Here, I will only show you how to retrieve the weather forecast.

Initial Title
Find Weather Forecast from IP Address

Initial Tags
ip

Initial Language
PHP