Loading Image

Almost there...

Loading Image

Loading...

Get user Location Information

This PHP script uses the current users IP address to get the location information about that user. It send the ip address to ipinfo.io and receive an array back with users location information.
20 March 2017 - 10:00
Downloads: 447
Category: PHP
Get user Location Information
Overview

This PHP script uses the current users IP address to get the location information about that user. It send the ip address to ipinfo.io and receive an array back with users location information.

PHP Code:
<?php
//#################################################################
//GET LOCATION DATA
//#################################################################
function getLocationData($url) {
	$ch = curl_init();
	$timeout = 5;
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	$data = curl_exec($ch);
	curl_close($ch);
	return $data;
}

$location_content	= json_decode($this->getLocationData('http://ipinfo.io/'.$ipOfUser), true);

echo $location_content;
?>