ajax php 聊天室实例代码(1)
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
- $disonline = true;
-
- $leastnum = 30;
-
- $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();?>'."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;
- }
|