查询卡号剩余时间 - 在线工具
<p><button onclick="getRemainingTime()">查询剩余时间</button></p>
<p id="remaining-time"></p>
<script>
function getRemainingTime() {
// 发送 AJAX 请求
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
// 处理服务器返回的数据
let remainingTime = xhr.responseText;
document.getElementById('remaining-time').innerHTML = remainingTime;
}
};
xhr.open('GET', 'time.php');
xhr.send();
}
</script>
<!-- time.php -->
<?php
include 'con.php'; // 包含链接数据库的代码
$current_time = time();
$sql = 'SELECT expire FROM cardh WHERE id=1'; // 假设卡号为1
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_assoc($result);
$expire_time = strtotime($row['expire']);
$remaining_time = $expire_time - $current_time;
echo '剩余时间:' . $remaining_time . '秒';
mysqli_close($con);
?>
原文地址: https://www.cveoy.top/t/topic/mubG 著作权归作者所有。请勿转载和采集!