PHP program hundred lines of code to quickly build a simple chat room method. Basic functions: logging in, chatting, recording online user IP events, controlling the chat font color, automatically converting the chat URL into a link address, and customizing the basic functions of the chat room Title and advertising letter: users can log on to chat, record online user IP events, control the font color of the chat, automatically convert the URLs in the chat into links, and customize the chat room Title and advertisement information. If you are interested in using text as a storage media, you can refer to the code and scale it out.
In fact, PHP is a great scripting language for rapid development!
=== Code ===
Reference content is as follows:
/**
* Simple chat room for night travelers
* Author: heiyeluren
* Creation:
* Modification:
*/
Error_reporting (7 );
Session_start ();
Header ("ContentType: text/html; charset = gb2312 ");
Define ("SCRIPT", $ _ SERVER ['script _ name']);
Define ("CHAT_NOTE", "./chat.txt ");
Define ("ONLINE_LIST", "./online.txt ");
Define ("REF_TIME", 5 );
Define ("CHAT_NAME", "night passers-by chat room ");
Define ("AD_MSG", "Today is Chinese Valentine's day. I wish you a happy Valentine's Day !! ");
// Obtain the value
If (isset ($ _ GET ['action']) &! Empty ($ _ GET ['action']) {
$ Action = $ _ GET ['action'];
}
// If you have logged on, jump to the chat page.
If (! Isset ($ _ GET ['action']) & isset ($ _ SESSION ['username']) {
Header ("location:". SCRIPT ."? Action = chat ");
}
// Logon prompt
If (! Isset ($ _ GET ['action'])
{
If (! Session_is_registered ('Username '))
{
Echo"
[". CHAT_NAME."]©2005
";
Exit;
}
}
// Verify login
If ($ action = 'login ')
{
If (isset ($ _ POST ['login _ user']) &! Empty ($ _ POST ['login _ user']) {
$ Username = $ _ POST ['login _ user'];
} Else {
$ Username = "tourist ";
}
Session_register ('Username ');
Save_online ($ username, get_client_ip ());
Header ("location:". SCRIPT ."? Action = chat ");
}
// Start chatting www.knowsky.com
If ($ action = "chat ")
{
$ Online_sum = get_online_sum ();
Echo"[". CHAT_NAME."]
". AD_MSG ."
[Currently online: $ online_sum]
Height = 60 scrolling = no frameborder = 0>
";
}
// Speaking interface
If ($ action = "say ")
{
Echo"[". CHAT_NAME."]
OnSubmit = 'return check () '>
[". $ _ SESSION ['username: Maxlength = 500 name = chatmsg style = 'background-color: #99CC99;
Width: 550px; height: 22px; border: 1px solid: #000000 '>
Default color Black quiet Red Passion Blue and cheerful Peach romance Green Youth Blue fresh Purple Dark night excitement Deep Blue and melancholy Khaki uniform Golden Years Ripple Blue-violet Suggestion of love ...