0

Is it possible to get the website visitor's location without using ip address ? I'm using geoplugin in my web app to get the visitors location using the IP address which I get from

$ip = $_SERVER['REMOTE_ADDR'];

but sometimes it does not return any data?

msanford
  • 11,803
  • 11
  • 66
  • 93
Jacob
  • 437
  • 1
  • 6
  • 21

3 Answers3

1

Yes ! Though without more details on your application, it's a bit hard to tell what to implement.

If this is a browser-based application, you could ask the browser to geolocate with navigator.geolocation.getcurrentposition and then send that data along with the request to php in the success callback.

Note that this call requires user permission, is asynchronous, and can take a long time to return.

Community
  • 1
  • 1
msanford
  • 11,803
  • 11
  • 66
  • 93
0

Try W3C Geolocation API

It is an effort by the World Wide Web Consortium (W3C) to standardize an interface to retrieve the geographical location information for a client-side device. It defines a set of objects, ECMAScript standard compliant, that executing in the client application give the client's device location through the consulting of Location Information Servers, which are transparent for the application programming interface (API).

The most common sources of location information are IP address, Wi-Fi and Bluetooth MAC address, radio-frequency identification (RFID), Wi-Fi connection location, or device Global Positioning System (GPS) and GSM/CDMA cell IDs. The location is returned with a given accuracy depending on the best location information source available.

Reference

Harikrishnan
  • 9,688
  • 11
  • 84
  • 127
0

You tried that $_SERVER['HTTP_X_FORWARDED_FOR']?

louk
  • 97
  • 6