<script>
    setInterval(function(){
        $.ajax({
            url: "your_php_file.php", //替换成你的PHP文件路径
            type: "POST",
            dataType: "json",
            data: {
                action: "update"
            },
            success: function(data) {
                $("#slzxrs").html(data.slzxrs);
                $("#sxcs").html(data.sxcs);
            },
            error: function(jqXHR) {
                console.log("Error: " + jqXHR.status);
            }
        });
    }, 3000); //3秒自动刷新
</script>
<h6><center><p>当前在线:<span id="slzxrs"><?php echo slzxrs(); ?></span> 人_ 累计观看人数:<span id="sxcs"><?php echo sxcs(); ?></span> 人</p></center></h6>
<?php
//在你的PHP文件里添加以下代码
if(isset($_POST['action']) && $_POST['action'] == 'update') {
    $slzxrs = slzxrs();
    $sxcs = sxcs();
    $data = array('slzxrs' => $slzxrs, 'sxcs' => $sxcs);
    echo json_encode($data);
    exit;
}
?>
把当前在线人数和累次观看人数的地方改成3秒自动实时更新 phpfunction sxcs$list = file_get_contentssxcsdat;$myfile = fopensxcsdat w;$sxcs = $list+1;fwrite$myfile$sxcs;fclose$myfile;return $sxcs;function slzxrs首先你要有读写文件的权限首次访问肯不

原文地址: https://www.cveoy.top/t/topic/b8aO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录