This article mainly introduces the use of GeoIP in Laravel to obtain the user's geographical location information, has a certain reference value, now share to everyone, the need for friends can refer to
I recently needed a user geo-detection to set the user's default region and currency. The Torann/geoip created by Daniel Stainback well meets the requirements for providing GEOIP services for Laravel 5 projects.
This Laravel GeoIP package supports a number of services, including the default ip-api.com service, a downloadable Maxmind database, and a Maxmind API. You can also easily add a generic service through this configuration.
The basic use of this package is the Reference geoip()
helper function, which optionally passes the IP address parameter. The following is an example of an IP address-based address object:
\torann\geoip\location { #attributes: array [ ' ip ' = ' 232.223.11.11 ', ' iso_code ' = ' US ' , ' country ' = ' states ', ' city ' and ' New Haven ', ' state ' = ' CT ' , ' State_name ' = ' and ' Connecticut ', ' Postal_Code ' and ' 06510 ' , ' lat ' = ' 41.28, ' Lon ' + -72.88, ' timezone ' = ' america/new_york ', ' continent ' = ' NA ', ' Currency ' = ' USD ', ' default ' = False, ]}
As you can see, the Address object contains some geographic information that helps determine the user's currency, time zone, and national ISO code.
If the destination address is not found, a configurable alternate address can be used instead, when the default
parameter is set to true
. You can override the default settings, as shown in the default configuration:
' Default_location ' = [ ' ip ' = ' 127.0.0.0 ', ' iso_code ' + ' US ', ' country ' and ' states ', c3/> ' city ' = ' New Haven ', ' state ' = ' CT ', ' state_name ' and ' Connecticut ', ' postal_code ' and ' = ' 06510 ', ' lat ' = + 41.31, ' lon ' and ' -72.92, ' timezone ' = ' america/new_york ', ' continent ' = > ' NA ', ' default ' = = True, ' currency ' = ' USD ',],
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!