Aayush Aayush - 11 months ago 57
PHP Question

Detect HTML5 Geolocation Support Using PHP

I need to detect HTML5 Geolocation support using PHP so that I can load a backup JavaScript that supports Geolocation using IP Address.

How to do this with or without PHP.


Have you considered using Modernizr to detect the HTML5 support? This isn't PHP specific since it's done in JavaScript but you can use this snippet to load your backup file:

if (Modernizr.geolocation){
   // Access using HTML5
   navigator.geolocation.getCurrentPosition(function(position) { ... });
   // Load backup file
   var script = document.createElement('script');
   script.src = '/path/to/your/script.js';
   script.type = 'text/javascript';
   var head = document.getElementsByTagName("head")[0];

(Based on http://www.modernizr.com/docs/#geolocation)