Skip to content
Advertisement

Get geolocation by Javascript and save it to text file via php

I want to get latitude and longitude of the guest and save them to a text file..

I used this:

JavaScript

but the result in the text file is :

JavaScript

with out any geolocation data

Any Help please?

Advertisement

Answer

This is totally not how it works. As javascript is client-side, and PHP is server-side, you can’t just do it the way you are trying to. You need to send that information to the server from client browser. The most common way, would be using ajax to POST javascript generatred content…

With jQuery it would be as easy as:

In html file…

JavaScript

In saver.php

JavaScript

PS. If you can’t or don’t want to use jQuery, please check this answer for information on how to use ajax in raw javascript.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement