Laravel using GeoIP to obtain the user's geo-location information

Source: Internet
Author: User
Tags geoip maxmind
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.