<!DOCTYPE html>
<head>
    <meta http-equiv='Content-Type' content='application/xhtml+xml; charset=utf-8; X-Wap-Proxy-Cookie=none' />
    <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
    <title>烧杯大厅</title>
    <link type='text/css' href='app/style/chat.css?v=1.2' rel='stylesheet' />
</head>
<body>
<div class='top'><span class='name'>烧杯在线聊天室(黑客手下留情)</span></div>
<?php
require_once 'app/app.php';
if(empty(@$_COOKIE[KEYS.'_name'])){
    echo '<div class='write login'>                
                <input type='text' value=''.rand_nick().'' id='nick' maxlength='5' placeholder='输入昵称...' />                
                <a href='javascript:;' id='login' class='write-link send'>进入</a>
</div>';          
} 
echo '<div class='talk mk-chat-box'>     
</div>
<div class='talk write'>                
                <input type='text' id='msg' maxlength='140' placeholder='聊点什么吧...' />                
                <a href='javascript:;' id='send' class='write-link send' onclick='send()'>发送</a>
</div>'; 
?>
<?php
function sxcs(){
    $list = file_get_contents('sxcs.dat');
    $myfile = fopen('sxcs.dat', 'w');
    $sxcs = ($list+1);
    fwrite($myfile,'$sxcs');
    fclose($myfile);
    return $sxcs;
}

function slzxrs(){
    //首先你要有读写文件的权限,首次访问肯不显示,正常情况刷新即可
    $online_log = 'slzxrs.dat'; //保存人数的文件到根目录,
    $timeout = 30;//30秒内没动则认为掉线
    $entries = file($online_log);
    $temp = array();
    for ($i=0;$i<count($entries);$i++){
        $entry = explode(',',trim($entries[$i]));
        if(($entry[0] != getenv('REMOTE_ADDR')) && ($entry[1] > time())) {
            array_push($temp,$entry[0].','.$entry[1].'
'); //取出其他浏览者的信息,并去掉超时者,保存进$temp
        }
    }
    array_push($temp,getenv('REMOTE_ADDR').','.(time() + ($timeout)).'
'); //更新浏览者的时间
    $slzxrs = count($temp); //计算在线人数
    $entries = implode('',$temp);
    //写入文件
    $fp = fopen($online_log,'w');
    flock($fp,LOCK_EX); //flock() 不能在NFS以及其他的一些网络文件系统中正常工作
    fputs($fp,$entries);
    flock($fp,LOCK_UN);
    fclose($fp);
    // echo '观看人数:'.$slzxrs.'人';
    return $slzxrs;
}

if(isset($_POST['msg'])){
    $msg = $_POST['msg'];
    if (strpos($msg, 'http') !== false) {
        $msg = '我是烧杯';
    }
    $nick = @$_COOKIE[KEYS.'_name'];
    $time = time();
    $msg = nl2br(htmlspecialchars($msg));
    if(strlen($msg) > 0){
        $content = '<p><span class='date'>'.date('H:i:s').'</span> <span class='nickname'>'.$nick.':</span> '.$msg.'</p>';
        $myfile = fopen('msg.dat', 'a') or die('Unable to open file!');
        fwrite($myfile, '<!--'.$time.'-->'.$content);
        fclose($myfile);
    }
}

?>
<div class='foot'>
消息实时更新,文明交流!当前在线:<?php echo slzxrs(); ?> 人_ 大厅用户:<?php echo sxcs(); ?> 人<p>禁止广告!打广告鸡巴短半截! <a href='./'>刷新</a></div>
<script src='app/style/jquery.min.js'></script>
<script src='app/style/chat.min.js'></script>
</body>
</html>
烧杯在线聊天室 - 畅聊无阻,文明交流!

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

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