0

I want to detect and insert location of the visitor on a webpage to a table in mysql. Tried many ways, research on internet but nothing explains how to insert into mysql.

Example: User Location John 'City','Country'

Sohal 07
  • 15
  • 4
  • My 1 second of research dug up a lot of nothing too: http://www.google.com/search?q=mysql+insert – Bailey Parker Jun 08 '12 at 08:03
  • 5
    The MySQL `INSERT` statement is a sacred, secret statement that is not documented at all. Tutorials describing the command are deleted by either Google or The Government, since it has to be passed on verbally from brogrammer to brogrammer. I'm sorry. – CodeCaster Jun 08 '12 at 08:05
  • 1
    I guess the problem is not the Mysql Insert, but finding the position of the visitor. Y U NO INSTALL GOOGLE ANALYTICS? – Roman Jun 08 '12 at 08:06
  • sorry guys..I meant to detect and insert.... I apologies for making it misundertanding...have just edited it – Sohal 07 Jun 08 '12 at 08:08
  • You cannot detect the location (define location) of the visitor, you can only guess it based on his or her IP address. There are databases out there that map IP addresses to locations (i.e. a country, city and perhaps a lat/lon). This is called Geolocation and is not precise, rarely up to date and it usually costs money. Simply implement Google Analytics, this wheel has been invented for you already. – CodeCaster Jun 08 '12 at 08:13
  • 1
    If the feature is not for statistical purpuoses, but an essential part of your application, you could always resort to the *new* `HTML5 Geolocation API` and call your application innovative. – Roman Jun 08 '12 at 08:32

1 Answers1

2

PHP can get the user's IP address via $_SERVER['REMOTE_ADDR'], you can compare this in a Geoloaction Database. Here is a list of databases.

Also note IPv6 was rolled out earlier this week, you might have to have two Geolocation databases.

Scott Stevens
  • 2,546
  • 1
  • 20
  • 29