Ajax PHP Chat Room Instance Code (1/5)

Source: Internet
Author: User
Tags php tutorial time interval ajax chat

<?php Tutorial
Ajax PHP Chat Room Instance Code
However, it must be based on the following terms:
Signature You must clearly indicate the author's name.
* Non-commercial use. You cannot use the current work for commercial purposes.
* Keep in line. If you change, transform, or construct a new work based on the current work, you should distribute the final work in exactly the same agreement as the current agreement
* For any two times use or distribution, you must let others clear the current work of the terms of the license
* With the explicit permission of the author, some provisions here can be waived

This convention is a simple and readable summary of the legal text (complete protocol)
Parameter Settings ****************
Show online users

The code is as follows Copy Code

$disonline = true;
Number of bars showing recent content when new login (default is 30)
$leastnum = 30;
Default room name (the default is to change a file every day), if you remove D, it is a month to change a file
$room = Date ("y-m-d");
Room save path, must end with/
$roomdir = "rooms/";
Encoding method
$charset = "Utf-8";
Maximum number of client display items (not recommended too large)
$maxdisplay = 300;

$lang = Array (
Chat Room Description
"description" => "Welcome to the mini Ajax chat room. Latest Version 1.2. Download please go to <a href= ' http://111cn.net ' target=_blank>www.111cn.net</a> ',
Chat room Title
"title" => "Mini Ajax Chatroom by Longbill",
The first welcome to the chat room
"Firstone" => "<span style= ' color: #16a5e9; ' >welcome to Longbill ' s mini ajax Chatroom!</span> ",
Display when information has prohibited content
"Ban" => "I am a pig!",
Key words
"keywords" => "chat room, mini, small, ajax,chat,chatroom,longbill,111cn.net,php, web Effects",
Speaking tips
"Hereyourwords" => "here to speak!"

Error_reporting (e_all ^ e_notice ^ e_warning);
Header ("content-type:text/html; Charset=utf-8 ");

$get _past_sec = 3; If you find lost words, you can adjust the value of the appropriate size
$touchs = 10; Check the time interval for online numbers

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;

Home 1 2 3 4 5 last
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.