PHP program hundred lines of code to quickly build a simple chat room method _php Tutorial

Source: Internet
Author: User
basic functions: Can log in, chat, record the number of online IP events, can control the font color of chat, automatically convert the URL of the chat as a link address, can customize the chat room title, advertising information and so on. Use text as a storage medium, and interest can refer to the code and expand it.

In fact, PHP as a fast-developing scripting language is great!

= = = Code = =

The following is the referenced content:
/**
* Night passers-by simple chat room
* Author: Heiyeluren
* Created: 2005-8-10 22:42
* Modified: 2005-8-11 23:25
*/
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 Passerby chat room");
Define ("Ad_msg", "Today is Chinese Valentine's Day, wish everyone Happy Valentine's Day!!");

Get value
if (Isset ($_get[' action ')) &&!empty ($_get[' action ')) {
$action = $_get[' action '];
}

If you have already logged in, jump directly to the chat screen.
if (!isset ($_get[' action ')) && isset ($_session[' username ']) {
Header ("Location:".) SCRIPT. "? Action=chat ");
}

Login Tips
if (!isset ($_get[' action '))
{
if (!session_is_registered (' username '))
{
echo "

[ ". Chat_name. "] ©2005




";
Exit
}
}

Check 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. "
[Current online: $online _sum]
<iframe src="".SCRIPT."?action=say" name="say_win" width="800<br"></iframe>height=60 Scrolling=no frameborder=0>
";
}

Speaking interface
if ($action = = "Say")
{
echo "[ ". Chat_name. "]



Onsubmit= ' return check () ' >
[". $_session[' username ']."] Said: maxlength=500 name=chatmsg style= ' background-color: #99CC99;
width:550px; height:22px; border:1px Solid: #000000 ' >
Default color Black Silence Red Passion Blue and cheerful Peach Romance Green Youth Cyan Refreshing Purple formality Night Excitement Blue Blues Khaki Uniform Gold-filled years Lake Wave Ripples Shiny Blue Violet The hint of love Http://www.bkjia.com/PHPjc/814352.htmlWww.bkjia.comTrueHttp://www.bkjia.com/PHPjc/814352.htmlTecharticleBasic functions: Can log in, chat, record the number of online IP events, can control the font color of chat, automatically convert the URL of the chat as a link address, can customize the chat room title, advertising letter ...

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.