PHP design chat room step by step

Source: Internet
Author: User
The chat room can run in a complete and free way. you can enter the room without a password or keep your chat status. the advantage is: freedom, which is very suitable for tourists! Another method is to register a chat room. every person who enters the chat room must enter his/her own

The chat room can run in a complete and free way. you can enter the room without a password or keep your chat status. the advantage is: freedom, which is very suitable for tourists! Another method is to register a chat room. every user who enters the chat room must enter his/her username and password! Strengths: it fully reflects the personality and is very suitable for old friends. what do they say will not be maliciously infringed on applications? my chat room app registration method!

Registration usually adopts two methods:

1. Register before chatting
    
2. active registration

Then modify your materials in it! I use 2nd methods !! The username of each new chat user will be automatically retained to the database. you must enter an accurate password for the next login!

The following is the judgment part! This program applies the text database!

//
//
//
//
//

// Enter the login parameter
If (= 'enter ')
{
// Current time in seconds
= Date ('u ');

// Lock the number of online users file to prevent simultaneous correction of the same file
While (file_exists ())
{
If (! File_exists ())
{
Break;
}
}

// Create a temporary file
Fclose (fopen (, 'w '));

// Read the information of online users and registered users: password, nickname, and update time
= File ();
= File ();

// Mark used to determine whether the login is successful
= 0;

// Determine the user name. The password is incorrect. the user name cannot be blank or exceed 10 characters. the password cannot exceed 20 characters.
If (= '') | (strlen ()> 10) | (strlen ()> 20 ))
{
Print ('No nickname or long password ');
// Login failed
= 1;
// Delete a temporary file
Unlink ();
}
Else
{
// Check whether someone has registered or the password is incorrect.
= 0;
For (= 0 ;();)
{
// Split
= Split (, 99 );
// Find the registered user name
If (=)
{
// The tag has been found.
= 1;
// Is the password correct?
If (! =)
Print ('wrong password! ');
// Login failed
= 1;
Unlink ();
Break;
}
Else
{
// Old user login successful
= 0;
Break;
}
}

}

// If the user name is not found, register it.
If (!)
{
// Retain the user name and password
= Fopen (, 'A ');
Fputs (,'');
Fclose ();
// New user login successful
= 0;
}
}
}
If (!)
{
// Update the list of online users
= Fopen (, 'w ');

// Determine whether it is already in, just refresh the page
= 0;
For (= 0 ;();)
{
= Split (, chop (), 99 );
If (=)
{
// Update the tag
= 1;
Fputs (,);

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.