<? Php tutorial
/*
Ajax php chat room instance code
However, it must be based on the following terms:
* Signature. You must specify the author's name ..
* Non-commercial use. You cannot use your current work for commercial purposes.
* Consistency. If you change, transform, or construct a new work based on the current work, you shall distribute the final work according to the agreement identical with the current agreement.
* For any secondary use or distribution, you must allow others to clarify the terms of authorization for the current work.
* With the explicit permission of the author, some of the terms here can be waived.
This agreement is a simple and easy-to-read summary of the legal text (complete agreement)
****************************************/
****************
// Display online users
$ Disonline = true;
// The number of recent content displayed upon New Login (30 by default)
$ Leastnum = 30;
// The default room name (a file is changed every day by default). If d is removed, a file is changed every month.
$ Room = date ("y-m-d ");
// Save path of the room, which must end with a slash (/)
$ Roomdir = "rooms /";
// Encoding method
$ Charset = "UTF-8 ";
// Maximum number of content displayed on the client (not too large recommended)
$ Maxdisplay = 300;
// Language
$ Lang = array (
// Chat room description
"Description" => "welcome to the mini ajax chat room. The latest version is 1.2. Download <a href = 'HTTP: // bKjia. c0m' target = _ blank> www. bKjia. c0m </a> ",
// Chat room title
"Title" => "mini ajax chatroom by longbill ",
// First welcome to the chat room
"Firstone" => "<span style = 'color: #16a5e9; '> welcome to longbill's mini ajax chatroom! </Span> ",
// Display the information when the content is forbidden
"Ban" => "I am a pig! ",
// Keyword
"Keywords" => "chat room, Mini, small, ajax, chat, chatroom, longbill, bKjia. c0m, php, webpage special effect ",
// Prompt
"Hereyourwords" => "here! "
);
Error_reporting (e_all ^ e_notice ^ e_warning );
Header ("content-type: text/html; charset = UTF-8 ");
$ Get_past_sec = 3; // you can increase the value if any loss occurs.
$ Touchs = 10; // check the time interval of online users
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