<?php教程
/*
ajax php 聊天室實例代碼
但是必須基於以下條款:
* 署名。你必須明確標明作者的名字。.
* 非商業用途。 你不可將當前作品用於商業目的。
* 保持一致。 如果你基於當前作品更改、變換或構造新作品,你應當按照與當前協議完全相同的協議分發最終作品
* 對於任何二次使用或分發,你必須讓其他人明確當前作品的授權條款
* 在得到作者的明確允許下,這裡的某些條款可以放棄
此約定是法律文本 (完整的協議)的簡單易讀概要
****************************************/
//****************參數設置****************
//顯示在線用戶
$disonline = true;
//新登陸時顯示最近內容的條數(默認為30條)
$leastnum = 30;
//默認的房間名(默認是每天換一個文件),如果去掉d,則是每月換一個文件
$room = date("y-m-d");
//房間保存路徑,必須以/結尾
$roomdir = "rooms/";
//編碼方式
$charset = "utf-8";
//客戶端最大顯示內容條數(建議不要太大)
$maxdisplay = 300;
//語言
$lang = array(
//聊天室描述
"description"=>"歡迎來到迷你ajax聊天室。最新版本 1.2。下載請到<a href='http://bKjia.c0m' target=_blank>www.bKjia.c0m</a>",
//聊天室標題
"title"=>"mini ajax chatroom by longbill",
//第一個到聊天室的歡迎
"firstone"=>"<span style='color:#16a5e9;'>welcome to longbill's mini ajax chatroom!</span>",
//當信息有禁止內容時顯示
"ban"=>"i am a pig!",
//關鍵字
"keywords"=>"聊天室,迷你,小型,ajax,chat,chatroom,longbill,bKjia.c0m,php,網頁特效",
//發言提示
"hereyourwords" => "在這裡發言!"
);error_reporting(e_all ^ e_notice ^ e_warning);
header("content-type:text/html; charset=utf-8");$get_past_sec = 3; //如果發現丟話,可以適當調大這個值
$touchs = 10; //檢查在線人數的時間間隔
if (!function_exists("file_get_contents"))
{
function file_get_contents($path)
{
if (!file_exists($path)) return false;
$fp=@fopen($path,"r");
$all=fread($fp,filesize($path));
fclose($fp);
return $all;
}
}if (!function_exists("file_put_contents"))
{
function file_put_contents($path,$val)
{
$fp=@fopen($path,"w");
fputs($fp,$val);
fclose($fp);
return true;
}
}
$title = $lang["title"];
$earlier = 10;
$description = $lang["description"];
$origroom = $room;
$least = ($_get["dis"])?intval($_get["dis"]):$leastnum;
$touchme = $_post['touchme'];
if (!is_dir($roomdir)) @mkdir($roomdir) or die("error when creating folder $roomdir");
$room = $_get['room'];
if (!$room) $room = $_post["room"];
$room = checkfilename($room);
if (!$room) $room = $origroom;
$filename = $roomdir.$room.".dat.php";
$datafile = $roomdir.$room.".php";
if (!file_exists($filename)) @file_put_contents($filename,'<?php die();?>'."n".time()."|".$lang["firstone"]."n");
if (!file_exists($datafile)) @file_put_contents($datafile,'<?php die();?>'."n");
$action = $_post["action"];function checkfilename($file)
{
if (!$file) return "";
$file = trim($file);
$a = substr($file,-1);
$file = eregi_replace("^[.\/]*","",$file);
$file = eregi_replace("[.\/]*$","",$file);
$arr = array("../","./","/","\","..\",".\");
$file = str_replace($arr,"",$file);
return $file;
}
1 2 3 4 5