Ajax php chat room instance code (1/5)

Source: Internet
Author: User
Tags ajax chat

<? 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

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.