程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 用PHP和ACCESS寫聊天室(一)

用PHP和ACCESS寫聊天室(一)

編輯:關於PHP編程

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{
        $ConnID=@odbc_connect("jtfcht","admin","");
        if ($ConnID){
            $result=@odbc_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 onload="NameGotFocus()">
<p> </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="cht.jpg" WIDTH="192" HEIGHT="384"></td>
        <td height="170" align="middle">
            <embed src="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%"> </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%"> </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%"> </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>  

【本文版權歸作者與奧索網共同擁有,如需轉載,請注明作者及出處】    

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved