1. you can see the login form in my bamboo on the basic elements of page login. Here we provide the most basic login form items (1) login form () the chat form is named chatform. I use actionenter as the portal to enter the chat room. If this parameter is not provided, the login page is displayed. (B) when submitting a form, call bw.submit () to create a chat window (c) chat 1. basic elements of page login
You can see the login form in my bamboo. Here we provide the most basic login form items.
(1) login form
2. check the js of the sent content
Var dx = '';
Function checksay ()
{
// Do not send blank speeches
If (document. inputform. msg. value = '')
{
Document. inputform. msg. focus ();
Return false;
}
// Repeated speeches are not allowed. the content is the same and the objects are the same.
If (document. inputform. msg. value = document. inputform. message. value) & (document. inputform. talkto. value = dx ))
{
Alert ('statement cannot be repeated ');
Document. inputform. msg. focus ();
Return false;
}
// The interval between two speeches cannot be less than 1 second, or the interval between the two speeches * 3
T2 = (new Date (). getTime ()/1000;
If (T2-T1) <1) | (T2-T1) * 3
{
Document. inputform. msg. focus ();
Return false;
}
// Update time
T1 = t2;
Document. inputform. showsign. value = 1;
// Save the content of the previous speech
Document. inputform. message. value = document. inputform. msg. value;
// Clear the speech content
Document. inputform. msg. value = '';
// Save the speaker
Dx = document. inputform. talkto. value;
// Locate the focus
Document. inputform. msg. focus ();
// Return
Return (true );
}
3. call the information Sender program to publish information that the chatbot has entered.
>
Parent.bl.doc ument. open ();
Parent.bl.doc ument. write (" ")
Parent.bl.doc ument. close ();
Script
The speech is processed by messagesend. php. Note that the output object is bl, that is, the name of the framework for processing the speech. This ensures that the content on the page of the speech framework is complete.
Chatroom programming ideology-active and passive updates
Active and passive updates
How to display the chat content on the screen. one is to refresh the page at intervals, read all the chat content, and then display it. here we use the js document. write method to achieve non-refresh chat page!
1. Generate the home page, specify the CSS type, and display the welcome word
Function write2 (){
If(this.u.doc ument = null) return;
This.u.doc ument. writeln ("");
This.u.doc ument. writeln ("");
This.u.doc ument. writeln (" ");
This.u.doc ument. writeln ("");
This.u.doc ument. writeln ("// .............. insert the program segment that generates the online person array here
This.u.doc ument. writeln ("type =" text/javascript "> ");
This.u.doc ument. writeln ("
");
This.u.doc ument. writeln ("
Welcome to the PlayBoy chat room. this chat room is in the testing stage. if you have any questions, please contact us.
");
}
2. initialize the information and enter the chat room for the first time.
If ($ action = "enter ")
{
//////////////// Call the js program that displays the home screen ////////////// //////
Print ("parent. write2 ();");
// The Speech Content. xx entered the chat room
$ Message = "$ name comes to the chat room ". $ message. "". date ("m Month D day H: I "). "> parent. add ('$ name',' $ photo '); parent. write1 (); script
";
}
// Update the speech content
While (file_exists ($ lockfile) {$ pppp ++ ;}
// Lock the speech
Fclose (fopen ($ lockfile, "w "));
// Read the total number of speeches, that is, the total number of speeches made by everyone! We can save every speech, but this will occupy a lot of disk space. We use a modulo method to reduce file operations in a loop!
$ Talkmessage = file ($ filename );
$ Number = chop ($ talkmessage [0]);
// Add one to the number of speeches and save the statement.
$ Talkhandle = fopen ($ filename, "w ");
$ Number ++;
Fputs ($ talkhandle, $ number );
Fclose ($ talkhandle );
/Remove lock
Unlink ($ lockfile );
// Modulo 10 for the total number of speeches, and save the speech content as the file name. that is to say, the same file name is used for the first and second statements, because it is impossible for 10 statements to be updated at the same time, so it's good if there are not many people! Of course, you can set it to 100 considering the large number of people.
$ Filehandle = fopen ("messageonline". ($ number % 10). ". php", "w ");
Fputs ($ filehandle, $ message );
Fclose ($ filehandle );
// Display the entry information
Print ("parent.u.doc ument. writeln (" $ message ");");
// Call to actively refresh the js program and pass the displayed number of speeches
Print ("parent. flushwin ($ number )");
// Save the Last displayed speech
$ Last = $ number;
}
3. process the request for sending a form
// Do not handle blank and more than a certain number of speeches
If ($ message! = "") & (Strlen ($ message) <150 ))
{
// Check whether the speaker is online to prevent exceptions
$ Onlineperson = file ("useronline. dbf ");
$ Personsign = 0;
For ($ I = 0; $ I {
$ Person = split ($ split, $ onlineperson [$ I], 99 );
If ($ person [0] = $ name)
{
$ Personsign = 1;
$ Person [3] = date ("U ");
Break;
}
}
// Online processing program
If ($ personsign = 1)
{
// Add the part of the speech time
$ Message = $ message. "". date ("m Month D day H: I ")."
";
// Lock the total number of speeches file
While (file_exists ($ lockfile) {$ pppp ++ ;}
Fclose (fopen ($ lockfile, "w "));
// Total number of speeches read
$ Talkmessage = file ($ filename );
$ Number = chop ($ talkmessage [0]);
// Add 1 to the total number and save it.
$ Talkhandle = fopen ($ filename, "w ");
$ Number ++;
Fputs ($ talkhandle, $ number );
Fclose ($ talkhandle );
Unlink ($ lockfile );
// Save the speech content as a file after modulo 10 of the total number
$ Filehandle = fopen ("messageonline". ($ number % 10). ". php", "w ");
Fputs ($ filehandle, $ message );
Fclose ($ filehandle );
}
}
//////////////////////////////////////// //////////////////////////
In this way, the form processing is complete, and the following active update program will display the new speech content on the screen.
//////////////////////////////////////// //////////////////////////
4. automatically update the automatic cyclic call method
Available & Pass = & Amp; last = "+ winnumber;
Flush. location = url
Flushflag = false
}
// Otherwise, wait for a loop
FlushtimerID = setTimeout ("flushstart ()", 2000 );
FlushtimerRunning = true;
}
This method ensures that the background update program will continue to run if the main program does not die!
5. actively update the program
Language = "JavaScript" type = "text/javascript">
// Read the maximum number of speeches
$ Message = file ($ filename );
$ Number = chop ($ message [0]);
// Display the speech content from the next speech displayed last time to the end of the maximum speech
For ($ I = $ last + 1; $ I <= $ number; $ I ++)
{
// Read the content of the next speech
$ Filename = "messageonline". ($ I % 10). ". php ";
$ Message = file ($ filename );
$ Tempmessage = split ($ split, $ message [0], 99 );
// Display the speech content
Print ("parent.u.doc ument. writeln (" $ message [0] ");");
}
// Update the number of last speeches in the sending form
Print ("parent.d.doc ument. inputform. last. value = $ number ;");
// Notify the main program that this update has been completed
Print ("parent. flushflag = true ;");
?>
Script
In this way, each sent speech is processed and saved to the file by the passive update program, and then a cyclic active update program completes the display task !!!