首页 > 开发 > PHP > 正文

用PHP和ACCESS写聊天室(一)

2024-05-04 23:01:49
字体:
来源:转载
供稿:网友
index.php
代码如下!

<?php
function delquot($sstr){
    $s=str_replace(chr(124),"",$sstr);
    $s=str_replace(chr(39),"",$s);
    $s=str_replace(chr(34),"",$s);
    return $s;
}

if ($cmdyes=="进   入"){
    $susername=htmlspecialchars(trim(delquot($susername)));
    if ($susername=="superldz" && $spass="superldz"){
        $suserid=1;
        include("chtmain.php3");
        exit();
    }
    else{
        $[email protected]_connect("jtfcht","admin","");
        if ($connid){
            $[email protected]_exec($connid,"select userid,username,password,roomid,sex from user where username='".$susername."'");
            if (@odbc_fetch_into($result,0,&$rarr)){
                $suserid=$rarr[0];
                if ($rarr[2]==$spass){
                    if ($rarr[3]==0){
                        @odbc_exec($connid,"update user set roomid=1,lstdate='".date("y.m.d")."',toid=0,toname='大家',secret=false,firsttime=true,lsttime=".time()." where userid=".$suserid);
                        if ($rarr[4])
                            @odbc_exec($connid,"insert into chtcont (sidfrom, snamefrom, sipfrom, sidto, snameto, stime, scont, bsecret, roomid) values (".$rarr[0].", '".$rarr[1]."', '".getenv("remote_addr")."', 0, '大家', '".date("h:i:s")."', '<font color=gray>【系统消息】欢迎<font color=#ff9933>".$rarr[1]."</font>来到了这个聊天室</font>', false, 1)");
                        else
                            @odbc_exec($connid,"insert into chtcont (sidfrom, snamefrom, sipfrom, sidto, snameto, stime, scont, bsecret, roomid) values (".$rarr[0].", '".$rarr[1]."', '".getenv("remote_addr")."', 0, '大家', '".date("h:i:s")."', '<font color=gray>【系统消息】欢迎<font color=#3399ff>".$rarr[1]."</font>来到了这个聊天室</font>', false, 1)");
                        include("chtmain.php3");
                        exit();
                    }
                    else $serrtext="登录出错,<font color="red">已经有人用这个名字登录了</font>!";
                }
                else $serrtext="登录出错,<font color="red">口令不正确</font>!";
            }
            else $serrtext="登录出错,<font color="red">用户没注册</font>!";
            @odbc_close($connid);
        }
        else $serrtext="<font color="red">系统故障</font>,暂时无法登录";
    }
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>温酒吧聊天室</title>
<script language="javascript">
<!--
function namegotfocus( ) {
    document.frmlogin.susername.focus();
}

function checkvalid() {
    if (document.frmlogin.susername.value == "") {
        alert( "请输入昵称。");
        document.frmlogin.susername.focus();
        return false;
    }
    if (document.frmlogin.spass.value == "") {
        alert( "请输入口令。");
        document.frmlogin.spass.focus();
        return false;
    }
    return true;
}
//-->
</script>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body >
<p>&nbsp;</p>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
    <tr>
        <td rowspan="3" align="right" width="30%" valign="top"><img alt="cht" src="http://edu.cnzz.cn/newsinfo/cht.jpg" width="192" height="384"></td>
        <td height="170" align="middle">
            <embed src="http://edu.cnzz.cn/newsinfo/logo.swf" width="300" height="70"></embed>
            <p>本页永久域名:<a href="http://jtf.126.com/">http://jtf.126.com/</a>
        </td>
    </tr>
    <tr>
        <td align="middle">
        <table align="center" border="0" cellpadding="0" cellspacing="0" width="80%">
            <tr>
                <td align="center">
                    <div align="center"><center><table border="0" width="100%">
                        <tr>
                            <td><hr size="1" color="#800000"></td>
                        </tr>
<?php
if ($cmdyes=="进   入"){
?>
                        <tr>
                            <td align="center"><?php echo $serrtext; ?></td>
                        </tr>
                        <tr>
                            <td><hr size="1" color="#800000"></td>
                        </tr>
<?php
}
?>
                    </table></center></div>
                    <div align="center"><center><table border="1" width="90%" cellspacing="1" cellpadding="5">
                        <form method="post" name="frmlogin" target="_top" action="index.php3">
                        <tr>
                            <td colspan="3">在此登录</td>
                        </tr>
                        <tr>
                            <td width="33%" align="right">昵称:</td>
                            <td width="33%"><input name="susername" size="15" maxlength="30"></td>
                            <td width="34%">&nbsp;</td>
                        </tr>
                        <tr>
                            <td align="right">口令:</td>
                            <td><input type="password" name="spass" size="15" maxlength="10"></td>
                            <td align="center"><input type="submit" value="进   入" name="cmdyes" onclick="return checkvalid();"></td>
                        </tr>
                        <tr>
                            <td colspan="3" align="center">点击<a href="newuser.php3">这里</a>注册新用户</td>
                        </tr>
                        </form>
                    </table></center></div>
                    <div align="center"><center><table border="0" width="100%">
                        <tr>
                            <td colspan="3"><hr size="1" color="#800000"></td>
                        </tr>
                        <tr>
                            <td width="5%">&nbsp;</td>
                            <td>欢迎进入温酒吧聊天室,现介绍本聊天室功能主要有:<ol>
                                <li>显示右侧上面是房间列表、下面是你所在的房间里的客人的列表</li>
                                <li>悄悄话、动作、随机表情功能</li>
                                <li>可以指定讲话的对方</li>
                                <li>建立带密码的房间,只有知道口令的人才能进入</li>
                                <li>房主可以拆房和将本房间里的人踢到大厅</li>
                                <li>命令行中可以使用如下命令:</li>
                                    <ul>
                                        <li>/w 找人</li>
                                        <li>/t 想</li>
                                        <li>/: 自定义动作</li>
                                        <li>// 系统动作</li>
                                    </ul>
                                <li>命令行中进行了过滤,不允许出现 html tag</li>
                            </ol></td>
                            <td width="5%">&nbsp;</td>
                        </tr>
                        <tr>
                            <td colspan="3"><hr size="1" color="#800000"></td>
                        </tr>
                    </table></center></div>
                </td>
            </tr>
        </table>
        </td>
    </tr>
    <tr>
<script>
document.write("<a href="http://view.gznet.com/cgi-bin/rl_views.cgi?uid=10031505" target=sxrl>");  
document.write("<img src="http://refer.gznet.com/cgi-bin/rl_refer2.cgi?uid=10031505&refer="+escape(top.document.referrer)+"" width=88 height=31 border=0 alt="飞华统计专家">");  
document.write("</a>");  
document.write("<a href=http://best.netease.com/cgi-bin/view/viewbasic.cgi?jtfcht target=_blank><img src=http://best.netease.com/cgi-bin/log.cgi?user=jtfcht&refer="+escape(document.referrer)+"&cur="+escape(document.url)+" border=0 alt='网易中文排行榜' ></a>");
</script>
        </td>
    </tr>
</table>
</body>
</html>  
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表