ajax php 聊天室執行個體代碼(1/5)

來源:互聯網
上載者:User

<?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://111cn.net' target=_blank>www.111cn.net</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,111cn.net,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();?>'." ".time()."|".$lang["firstone"]." ");
if (!file_exists($datafile)) @file_put_contents($datafile,'<?php die();?>'." ");
$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 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.