/ Published in: PHP
                    
                                        
// description of your code here
/********************************************************************************/
/* Description: Get Longitude and Latitude by IP address in PHP */
/* For information, please visit http://www.ip2location.com */
/********************************************************************************/
                /********************************************************************************/
/* Description: Get Longitude and Latitude by IP address in PHP */
/* For information, please visit http://www.ip2location.com */
/********************************************************************************/
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
// description of your code here
/********************************************************************************/
/* Description: Get Longitude and Latitude by IP address in PHP */
/* For information, please visit http://www.ip2location.com */
/********************************************************************************/
<?php
$api_key = "insert api key here";
$ip_addr = get_remote_ip_address();
//Only IP2Location Web Service package WS5, WS9 and WS10 contains latitude and longitude information
$package = "insert package number";
$service_url = "http://api.ip2location.com/?ip=$ip_addr&key=$api_key&package=$package";
//Setting up connection using the service url
$temp = $result;
//Retrieving latitude and longitude information from the result returned by the API
$latitude = $result_split[4];
$longitude = $result_split[5];
echo $temp . "<br />";
echo "latitude : " . $latitude . "<br />";
echo "longitude : " . $longitude . "<br />";
function get_remote_ip_address()
{
// Check to see if an HTTP_X_FORWARDED_FOR header is present.
if($_SERVER['HTTP_X_FORWARDED_FOR'])
{
// If the header is present, use the last IP address.
}
else
{
// If the header is not present, use the
// default server variable for remote address.
$temp_ip_address = $_SERVER['REMOTE_ADDR'];
}
return $temp_ip_address;
}
?>
URL: http://www.ip2location.com
Comments
 Subscribe to comments
                    Subscribe to comments
                
                