Show results from user site

I would like to show results from a DB

visiting user city

, I have 2 ideas for this.

  • First, ask the user about the first visit to the website to select it using the javascript

    popup and save it in a cookie for later visit.

  • The second option is to use APIs IP to Location

    to automatically detect the user's current location and save the cookie using php.

I'm not sure which one will be the best, the second option is not 100%

accurate as the IP address can lead to an incorrect result.

Guys, please suggest how would you go? what data should be stored in the cookie?

any free API you prefer to receive in the user's current city.

+3


source to share


2 answers


There are several methods, including the ones you listed. It is recommended to obtain several methods to obtain the most accurate results.

In a recently completed project, we tried to locate the user and displayed this information in the site header, giving the user the option to click and modify it so they can point to the correct location if our discovery was inaccurate. We have implemented the following methods:



  • HTML5 Geolocation . This information is provided by the browser, however it will also prompt the user to ask them if they want to submit this information (at least in Firefox, I don't remember how other browsers behaved.)

  • PHP GeoIP . This server is server-side and usually gives results accurate to the city, but not always. In particular, if the user is using a mobile hotspot, it can detect them on the other side of the country.

  • If we could not find, exactly or otherwise, we would ask the user for this information (this particular application was dependent on this information, so there was no way to continue without knowing about it).

+2


source


I would suggest a combination of the two.

First, use an IP Geolocation API like IPInfoDB.com to locate the IP address.



Then provide information to users and ask them to update if the location is incorrect.

In this case, you will always get the location of the users.

0


source







All Articles