开发者

Is it possible for PHP to use the HTML 5 geolocation without using a javascript?

Is it be possible for php to use HTML 5 geolocation?

The idea is the navigator.geolocation can be used only using javascript.But what if the device turn off its javascript or no javascript support.

PHP can pull out the navigator.userA开发者_高级运维gent and they do it by $_SERVER['HTTP_USER_AGENT']. I dunno how they do it so there should be a way to use the PHP to access navigator.geolocation without using javascript.The question is how?

Thank you.


You cannot. Php works on server and haven't any access to client's browser.

Php's work is finished when html is completely generated. After that complete html is passed to the client through network.


Most browsers send the user-agent with the HTTP request, and that's why your server has access to the user agent.

But as far as I know, no browser sends location info along with the HTTP request, so your server script doesn't have access to that data.

The best you can do on the server without help of JavaScript is to guess the location based on the IP.

However, if your user has JavaScript enabled, you can send the location to the server somehow (like, AJAX request and store in session or profile, or store the coordinates in a hidden input field), and degrade to guessing by IP when the user doesn't have JavaScript enabled.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜