TimeZone

How to determine user geolocation data
How to determine user geolocation data

To determine the user's location, we need their IP address and a database with a list of IP addresses and their associated geographic data. However, since we've already implemented a solution using a database in this article, today we’ll make the task slightly more complex and interact with an external service via its API to retrieve all the information we need — time zone, latitude, longitude, country, and city.

read more...

How to determine the region by IP in PHP using the DB
How to determine the region by IP in PHP using the DB

In this article, we’ll look at one way to determine a user’s location based on their IP address — specifically, using an existing database of regions and assigned IP address ranges.

There are many such databases available. I happened to work with a database from ip2location.com. I can’t say anything bad about it — it correctly identified my region and those of some of my clients.

The first thing we need is to download the database file. They provide it in CSV format, and you can get it from this page.

Importing the IP and Region Data File

Follow the instructions in the description to save time. Initially, I tried importing the data via phpMyAdmin using CSV import, and that took significantly longer than a console-based import.

read more...

How to get time of all timezones in PHP
How to get time of all timezones in PHP

To get an array of all time zones with their time offset from Greenwich, use the following function:

function get_time_timezones()
{
	$zones_array = array();
	$timestamp = time();
	
	$default_timezone = date_default_timezone_get();
	$timezone_list = timezone_identifiers_list();
	
	foreach ($timezone_list as $zone)
	{
		date_default_timezone_set($zone);
		$zones_array[$zone] = date('P', $timestamp);
	}
	
	date_default_timezone_set($default_timezone);
	
	return $zones_array;
}

read more...