Php 将客户端位置保存到txt文件中

Php 将客户端位置保存到txt文件中,php,html,location,var,Php,Html,Location,Var,我正在尝试将“纬度”和“经度”值写入保存在我的服务器中的txt文件 我的代码是 <!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var x = document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator

我正在尝试将“纬度”和“经度”值写入保存在我的服务器中的txt文件

我的代码是

<!DOCTYPE html>
<html>
<body>



<p id="demo"></p>

<script>
var x = document.getElementById("demo");

function getLocation() {
    if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
    } else { 
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}

function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude;  
}
</script>

<script>
getLocation();
</script>



<?php
$handle = fopen("location", "a");
foreach ( $_GET as $key => $value ) 
{
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>

</body>
</html>

var x=document.getElementById(“演示”); 函数getLocation(){ if(导航器.地理位置){ navigator.geolocation.getCurrentPosition(showPosition); }否则{ x、 innerHTML=“此浏览器不支持地理位置。”; } } 功能显示位置(位置){ x、 innerHTML=“纬度:”+position.coords.Latitude+ “
经度:”+position.coords.Longitude; } getLocation();
每次访问html页面后,我都会得到一个空白文本文件
我希望将“position.coords.latitude”和position.coords.longitude写入txt文件

可能重复:首先,不要在一个文件中混合使用javascript、html和php代码。把它们分开。您得到的是空白文件,因为您没有为此做任何事情。你的javascript代码没有将经度和纬度发送到服务器(php代码)。@amol01你能告诉我怎么做吗?我是初学者,在编写代码之前,你最好先做一些教程。在那里你会发现很多。