基本功能:能登陸,聊天,記錄在線人數IP事件,能控制聊天的字體顏色,自動把轉化聊天中網址為鏈接地址,能定制聊天室標題、廣告信息等等。使用文本作為存儲媒體,又興趣可以參考代碼,並且進行擴展。
其實PHP作為快速開發的腳本語言是很棒的!
===代碼===
以下為引用的內容:
<?php
/**
* 黑夜路人簡易聊天室
* 作者: heiyeluren <heiyeluren_at_163.com>
* 創建: 2005-8-10 22:42
* 修改: 2005-8-11 23:25
*/
error_reporting(7);
session_start();
header("ContentType:text/html;charset=gb2312");
define("SCRIPT", $_SERVER['SCRIPT_NAME']);
define("CHAT_NOTE", "./chat.txt");
define("ONLINE_LIST", "./online.txt");
define("REF_TIME", 5);
define("CHAT_NAME", "黑夜路人聊天室");
define("AD_MSG", "今天是中國情人節, 祝大家情人節快樂!!");
//獲取值
if (isset($_GET['action']) && !empty($_GET['action'])) {
$action = $_GET['action'];
}
//如果已經登陸那麼直接跳到聊天界面
if (!isset($_GET['action']) && isset($_SESSION['username'])) {
header("location:".SCRIPT."?action=chat");
}
//登陸提示
if (!isset($_GET['action']))
{
if (!session_is_registered('username'))
{
echo " <p><h3 align=center>[ ".CHAT_NAME." ] © 2005</h3></p>
<p align=center>
<form action=".SCRIPT."?action=login method=post>
呢稱: <input type=text size=25 maxlength=30 name=login_user>
<input type=submit value=聊天>
</form></p>
";
exit;
}
}
//校驗登陸
if ($action=='login')
{
if (isset($_POST['login_user']) && !empty($_POST['login_user'])) {
$username = $_POST['login_user'];
} else {
$username = "游客";
}
session_register('username');
save_online($username, get_client_ip());
header("location:".SCRIPT."?action=chat");
}
//開始聊天www.knowsky.com
if ($action=="chat")
{
$online_sum = get_online_sum();
echo "<head><title>[ ".CHAT_NAME." ]</title></head><center>
<body bgcolor=#C4BFB9 style='font-size:12px;'>
<div style='border:1px solid #999966; width:802px;height:450'>
<iframe src='".SCRIPT."?action=show'
name=show_win width=800 height=450 scrolling=auto frameborder=0></iframe>
</div><br>
<marquee width=70% scrollamount=2> ".AD_MSG." </marquee>
[當前在線:$online_sum]
<iframe src='".SCRIPT."?action=say' name=say_win width=800
height=60 scrolling=no frameborder=0>
";
}
//說話界面
if ($action=="say")
{
echo "<head><title>[ ".CHAT_NAME." ]</title></head><center>
<body bgcolor=#C4BFB9 style='font-size:12px;'>
<form action=".SCRIPT."?action=save method=post name=chat
onSubmit='return check()'>
[".$_SESSION['username']."]說:<input type=text size=80
maxlength=500 name=chatmsg style=' background-color:#99CC99;
width:550px; height:22px; border:1px solid:#000000'>
<select name=usercolor>
<OPTION selected style='COLOR: #000000' value='000000'>默認顏色</OPTION>
<OPTION style='COLOR: #000000' value='#000000'>黑色沉靜</OPTION>
<option style='COLOR: #ff0000' value='#FF0000'>紅色熱情</option>
<option style='COLOR: #0000ff' value='#0000FF'>藍色開朗</option>
<option style='COLOR: #ff00ff' value='#FF00FF'>桃色浪漫</option>
<option style='COLOR: #009900' value='#009900'>綠色青春</option>
<option style='COLOR: #009999' value='#009999'>青色清爽</option>
<option style='COLOR: #990099' value='#990099'>紫色拘謹</option>
<option style='COLOR: #990000' value='#990000'>暗夜興奮</option>
<option style='COLOR: #000099' value='#000099'>深藍憂郁</option>
<option style='COLOR: #999900' value='#999900'>卡其制服</option>
<option style='COLOR: #ff9900' value='#FF9900'>镏金歲月</option>
<option style='COLOR: #0099ff' value='#0099FF'>湖波蕩漾</option>
<option style='COLOR: #9900ff' value='#9900FF'>發亮藍紫</option>
<option style='COLOR: #ff0099' value='#FF0099'>愛的暗示</option>