基本功能
其實PHP作為快速開發的腳本語言是很棒的!
===代碼===
<?php
/**
* 黑夜路人簡易聊天室
* 作者: heiyeluren <heiyeluren_at_
* 創建:
* 修改:
*/
error_reporting(
session_start();
header(
define(
define(
define(
define(
define(
define(
//獲取值
if (isset($_GET[
$action = $_GET[
}
//如果已經登陸那麼直接跳到聊天界面
if (!isset($_GET[
header(
}
//登陸提示
if (!isset($_GET[
{
if (!session_is_registered(
{
echo
<p align=center>
<form action=
呢稱: <input type=text size=
<input type=submit value=聊天>
</form></p>
exit;
}
}
//校驗登陸
if ($action==
{
if (isset($_POST[
$username = $_POST[
} else {
$username =
}
session_register(
save_online($username
header(
}
//開始聊天www
if ($action==
{
$online_sum = get_online_sum();
echo
<body bgcolor=#C
<div style=
<iframe src=
name=show_win width=
</div><br>
<marquee width=
[當前在線
<iframe src=
height=
}
//說話界面
if ($action==
{
echo
<body bgcolor=#C
<form action=
onSubmit=
[
maxlength=
width:
<select name=usercolor>
<OPTION selected style=
<OPTION style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
<option style=
</select>
<input type=submit value=
<a href=
target=_top onclick=
</form>
<script>function check(){if(document
{;alert(
}
//保存說話
if ($action==
{
if ($_POST[
save_chat($_POST[
}
header(
}
//顯示聊天記錄
if ($action==
{
echo
echo
CONTENT=
if (file_exists(CHAT_NOTE)) {
$chat_msg = @file_get_contents(CHAT_NOTE);
echo $chat_msg;
} else {
echo
}
}
//退出聊天室
if ($action==
{
unset($_SESSION[
session_destroy();
header(
}
/* 基本函數 */
//保存聊天記錄函數
function save_chat($msg
{
if (!$fp = fopen(CHAT_NOTE
die(
}
$msg = htmlspecialchars($msg);
$msg = preg_replace(
+\
<a href=\\
$msg = preg_replace(
+\
$msg = date(
<font color=
if (!fwrite($fp
die(
}
fclose($fp);
}
//寫在線人信息
function save_online($user
{
if (!$fp = fopen(ONLINE_LIST
die(
}
$user = str_replace(
$line = $user
if (!fwrite($fp
die(
}
fclose($fp);
}
//獲取在線人數
function get_online_sum()
{
if (file_exists(ONLINE_LIST)) {
$online_msg = file(ONLINE_LIST);
return count($online_msg);
} else {
return
}
}
//獲取當前登陸用戶IP
function get_client_ip()
{
if ($_SERVER[
$cip = $_SERVER[
} elseif (getenv(
$cip = getenv(
} elseif (getenv(
$cip = getenv(
} else {
$cip =
}
return $cip;
}
?>
From:http://tw.wingwit.com/Article/program/PHP/201311/21485.html