PHP program hundred lines of code to quickly build a simple chat room Method

Source: Internet
Author: User

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 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:
<? Php
/**
* 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 "<p>

<P align = center>
<Form action = ". SCRIPT ."? Action = login method = post>
<Input type = text size = 25 maxlength = 30 name = login_user>
<Input type = submit value = chat>
</Form> </p>
";
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 "<Body bgcolor = # C4BFB9 style = 'font-size: 12px; '>
<Div style = 'border: 1px solid #999966; width: 802px; height: 450 '>
<Iframe src = '". SCRIPT ."? Action = show'
Name = show_win width = 800 height = 450 scrolling = auto frameborder = 0> </iframe>
</Div> <br>
<Marquee width = 70% scrollamount = 2> ". AD_MSG." </marquee> & nbsp;
[Currently online: $ online_sum]
<Iframe src = '". SCRIPT ."? Action = say 'name = say_win width = 800
Height = 60 scrolling = no frameborder = 0>
";
}

// Speaking Interface
If ($ action = "say ")
{
Echo "<Body bgcolor = # C4BFB9 style = 'font-size: 12px; '>
<Form action = ". SCRIPT ."? Action = save method = post name = chat
OnSubmit = 'Return check () '>
[". $ _ SESSION ['username']."]: <input type = text size = 80
Maxlength = 500 name = chatmsg style = 'background-color: #99CC99;
Width: 550px; height: 22px; border: 1px solid: #000000 '>
<Select name = usercolor>
<OPTION selected style = 'color: #000000 'value = '000000'> default COLOR </OPTION>
<OPTION style = 'color: #000000 'value =' #000000 '> black silence </OPTION>
<Option style = 'color: # ff000000' value = '# ff000000'> Red enthusiasm </option>
<Option style = 'color: # 0000ff 'value =' # 0000FF '> blue and cheerful </option>
<Option style = 'color: # ff00ff 'value =' # FF00FF '> peach romance </option>
<Option style = 'color: #009900 'value =' #009900 '> green youth </option>
<Option style = 'color: #009999 'value =' #009999 '> cyan refreshing </option>
<Option style = 'color: #990099 'value =' #990099 '> purple </option>
<Option style = 'color: #990000 'value =' #990000 '> dark night excitement </option>
<Option style = 'color: #000099 'value =' #000099 '> deep blue and melancholy </option>
<Option style = 'color: #999900 'value =' #999900 '> card the uniform </option>
<Option style = 'color: # ff9900 'value = '# FF9900'> golden years </option>
<Option style = 'color: # 0099ff 'value =' # 0099FF '> Lake ripple </option>
<Option style = 'color: # 9900ff 'value =' # 9900FF '> shiny blue-violet </option>
<Option style = 'color: # ff0099 'value =' # FF0099 '> suggestion of love </option>

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.