The chat room can run in a completely free way. you can enter the name at will, without a password, and do not save your chat status. the advantage is: freedom, which is very suitable for tourists! Another method is to register a chat room. every person entering the chat room must enter his/her username and password before entering the room! Advantage: it fully reflects the personality and is very suitable for old friends. what do they say is that they will not be maliciously encroached on, so that the chat room can run in a completely free way. you can enter the name at will without a password, do not save your chat status, advantages: free, very suitable for tourists! Another method is to register a chat room. every person entering the chat room must enter his/her username and password before entering the room! Advantage: it fully reflects the personality and is very suitable for old friends. what do they say will not be maliciously occupied and used? my chat room uses the registration method!
Registration usually uses two methods: 1. Register first and then enter the chat; 2. automatically register, and then modify your own information in it! I use 2nd methods !! The username of each new user will be automatically saved to the database. you must enter an accurate password for the next login!
The following is the judgment part! This program uses a text database!
// $ Useronline is the name of the online user's data file
// $ Useronlinelock is the identifier of the online user
// $ Register is the name of the registered data file
// $ Registerlock indicates the lock mark of the registered file
// $ Split is the separator
// Enter the login parameter
If ($ action = "enter ")
{
// Current time in seconds
$ Timecurrent = date ("U ");
// Lock the number of online users file to prevent simultaneous modification of the same file
While (file_exists ($ useronlinelock ))
{
If (! File_exists ($ useronlinelock ))
{
Break;
}
}
// Create a temporary file
Fclose (fopen ($ useronlinelock, "w "));
// Read the information of online users and registered users: password, nickname, and update time
$ Useronline = file ($ useronline );
$ Register = file ($ register );
// Indicates whether the logon is successful.
$ Namesign = 0;
// Determine the user name. The password is incorrect. the user name cannot be blank, and cannot exceed 10 characters. the password cannot exceed 20 characters.
If ($ name = "") | (strlen ($ name)> 10) | (strlen ($ pass)> 20 ))
{
Print ("no nickname or long password ");
// Login failed
$ Namesign = 1;
// Delete a temporary file
Unlink ($ useronlinelock );
}
Else
{
// Check whether someone has registered or the password is incorrect.
$ Foundsign = 0;
For ($ I = 0; $ I {
// Split
$ Tempregister = split ($ split, $ register [$ I], 99 );
// Find the registered user name
If ($ name = $ tempregister [0])
{
// The flag has been found.
$ Foundsign = 1;
// Is the password correct?
If ($ pass! = $ Tempregister [1])
Print ("wrong password! ");
// Login failed
$ Namesign = 1;
Unlink ($ useronlinelock );
Break;
}
Else
{
// Old user login successful
$ Namesign = 0;
Break;
}
}
}
// If this user name is not found, it will be automatically registered
If (! $ Foundsign)
{
// Save the user name and password
$ Handle = fopen ($ register, "");
Fputs ($ handle, "$ name $ split $ pass $ splitrn ");
Fclose ($ handle );
// New user login successful
$ Namesign = 0;
}
}
}
If (! $ Namesign)
{
// Update the list of online users
$ Useronlinehandle = fopen ($ useronline, "w ");
// Judge whether it is already in, just refresh the page
$ Updatesign = 0;
For ($ I = 0; $ I {
$ Usertemp = split ($ split, chop ($ useronline [$ I]), 99 );
If ($ name = $ usertemp [0])
{
// Update the flag
$ Updatesign = 1;
Fputs ($ useronlinehandle, $ useronline [$ I]);
}
Else
{
Fputs ($ useronlinehandle, $ useronline [$ I]);
}
}
// If not, add it to it
If (! $ Updatesign)
Fputs ($ useronlinehandle, "$ name $ split $ level $ split $ pass $ split $ timecurren
Trn ");
Fclose ($ useronlinehandle );
// Remove the contraction
Unlink ($ useronlinelock );
// Login successful
}
At this point, the user verification has been completed, and the chat user has entered the chat room legally. what about the carrier name and password?
Original Author: howtodo
Source: php2000.com