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

Source: Internet
Author: User
Tags empty

basic functions: Can log in, chat, record the number of online IP events, can control the font color chat, automatic conversion chat URL for the link address, can be customized chat room title, advertising information and so on. Use text as a storage medium, and interest can refer to the code and expand.

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

= = = Code = =

The following are the referenced contents:
<?php
/**
* 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 passers-by chat room");
Define ("Ad_msg", "Today is Chinese Valentine's Day, wish everybody Happy Valentine's Day!!");

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

If you've logged in, skip to the chat interface.
if (!isset ($_get[' action ')) && isset ($_session[' username ')) {
Header ("Location:"). SCRIPT. "? Action=chat ");
}

Landing Tips
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
}
}

//Checksum login
if ($action = = ' Login ')
{
 if (isset ($_post[' Login_user ')) &&!empty ($_post[' Login_ User ']) {
  $username = $_post[' Login_user '];
 } else {
  $username = "Tourist";
 }
&N Bsp;session_register (' username ');
 save_online ($username, Get_client_ip ());
 header ("Location:"). SCRIPT. "? Action=chat ");
}

//Start chat www.knowsky.com
if ($action = = "Chat")
{
  $online _sum = Get_online_sum ();
 echo < Head><title>[". Chat_name. "] </title> <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;&NBSP;&NBSP
[current online: $online _sum]
   <iframe src= '". SCRIPT. "? Action=say ' Name=say_win width=800
height=60 scrolling=no frameborder=0>
 ;
}

The

//Speaker 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 ']."] said: <input type=text size=80
maxlength=500 name=chatmsg style= ' background-color: #99CC99;
width:550px; : 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>&NBSP
  <option style= ' COLOR: #ff0000 ' value= ' #FF0000 ' > Red Passion </option> 
  <option style= ' COLOR: #0000ff ' value= ' #0000FF ' > Blue 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 prim </option> 
  <option style= ' COLOR: #990000 ' value= ' #990000 ' > Night excitement </option> &NBSP
  <option style= ' COLOR: #000099 ' value= ' #000099 ' > Dark blue </option> 
  < Option style= ' color: #999900 ' value= ' #999900 ' > Khaki uniform </option> 
  <option style= ' color: # ff9900 ' value= ' #FF9900 ' > Gilded years </option> 
  <option style= ' COLOR: #0099ff ' value= ' #0099FF ' > Lake wave </option> 
  <option style= ' COLOR: #9900ff ' value= ' #9900FF ' > Shine Blue Violet </option> &NBSP
  <option style= ' COLOR: #ff0099 ' value= ' #FF0099 ' > Love hint </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.