如果你是一名程序员需要写html获取浏览器代理IPwebrtc获取真实IP用户进入时间所在国家所在城市自动提交至Php保存成json表格格式显示
以下是一份可能的代码示例:
HTML获取浏览器代理IP:
<!DOCTYPE html>
<html>
<head>
<title>获取浏览器代理IP</title>
<script>
function getProxyIP() {
var ip = "";
if (window.XMLHttpRequest) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.ipify.org?format=json", false);
xhr.send();
if (xhr.status == 200) {
var response = JSON.parse(xhr.responseText);
ip = response.ip;
}
} else {
ip = "XMLHttpRequest not supported";
}
document.getElementById("proxyIP").innerHTML = ip;
}
</script>
</head>
<body onload="getProxyIP()">
<h1>你的代理IP地址是:</h1>
<p id="proxyIP"></p>
</body>
</html>
WebRTC获取真实IP:
<script>
var pc = new RTCPeerConnection();
pc.createDataChannel("");
pc.createOffer(function(sdp) {
pc.setLocalDescription(sdp);
}, function() {});
pc.onicecandidate = function(event) {
if (event.candidate) {
var ip = event.candidate.candidate.split(" ")[4];
document.getElementById("realIP").innerHTML = ip;
}
};
</script>
获取用户进入时间、所在国家、所在城市:
<script>
var timestamp = new Date().getTime();
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://ipapi.co/json/", false);
xhr.send();
if (xhr.status == 200) {
var response = JSON.parse(xhr.responseText);
var country = response.country_name;
var city = response.city;
document.getElementById("time").innerHTML = timestamp;
document.getElementById("country").innerHTML = country;
document.getElementById("city").innerHTML = city;
}
</script>
自动提交至PHP保存成JSON表格格式显示:
<?php
$data = array(
"timestamp" => $_POST["timestamp"],
"proxyIP" => $_POST["proxyIP"],
"realIP" => $_POST["realIP"],
"country" => $_POST["country"],
"city" => $_POST["city"]
);
$json = json_encode($data);
$file = "data.json";
if (file_exists($file)) {
$handle = fopen($file, "a");
} else {
$handle = fopen($file, "w");
}
fwrite($handle, $json . "\n");
fclose($handle);
?>
<!DOCTYPE html>
<html>
<head>
<title>用户数据表格</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #ddd;
}
</style>
</head>
<body>
<h1>用户数据表格</h1>
<table>
<tr>
<th>时间戳</th>
<th>代理IP地址</th>
<th>真实IP地址</th>
<th>所在国家</th>
<th>所在城市</th>
</tr>
<?php
$file = "data.json";
if (file_exists($file)) {
$handle = fopen($file, "r");
while (!feof($handle)) {
$json = fgets($handle);
if (!empty($json)) {
$data = json_decode($json, true);
echo "<tr>";
echo "<td>" . $data["timestamp"] . "</td>";
echo "<td>" . $data["proxyIP"] . "</td>";
echo "<td>" . $data["realIP"] . "</td>";
echo "<td>" . $data["country"] . "</td>";
echo "<td>" . $data["city"] . "</td>";
echo "</tr>";
}
}
fclose($handle);
}
?>
</table>
</body>
</html>
请注意,这些代码示例可能需要根据您的实际需求进行修改和调整。此外,为了实现自动提交和保存用户数据,您需要将HTML代码和PHP代码保存在同一个文件中,并将HTML表单的“action”属性设置为PHP文件的路径。例如:
<form method="POST" action="save.php">
原文地址: https://www.cveoy.top/t/topic/bbWG 著作权归作者所有。请勿转载和采集!