Generally, personal free homepage space does not provide mysql support, that is, the supply is also very demanding, so it is very important to find a good exchange plan! PHP's file processing capabilities are powerful, so they can be replaced by file access! (You need to know that no number of personal free homepage space will not provide mysql support, that is, the supply is also very demanding, so it is very important to find a good exchange plan!
PHP's file processing capabilities are powerful, so they can be replaced by file access!
(When there is no database, all files are organized! Haha !), The data items are separated by special symbols. I use "|" to read a single record through The explode () function!
The database concept can still be used here! Like the database index!
Therefore, you must create an index file first! (This is not accurate)
Let's talk about it in the message book:
Important files:
Index. database
Its structure is as follows:
Name of the contact person | gender of the contact person | time of the contact person | feiyn!
Each row can be easily read using the fgets () function of PHP, or the file () function to read each row to the array.
To prevent conflicts between multiple users in writing data, you also need to apply a lock (also implemented using files)
Below is the code written
// The following parameters must be input:
// Name of the contact $ name
// Gender of the contact person $ ***
// Message time $ time
// Status of message content storage $ savePosite
$ IndexFile = 'index. database ';
$ IndexFileLock = $ indexFile. 'lock ';
$ Message = $ name. '| '. $ ***. '| '. $ time. '| '. $ savePosite. '| feiy |'; // This is the record to be written.
While (file_exists ($ indexFileLock) $ temp; // checks whether the lock has been applied.
Fclose (fopen ($ indexFileLock, 'w'); // If not, the system enters and locks to avoid visiting conflicts.
$ Fp = fopen ($ indexFile, 'A ');
Fputs ($ message, strlen ($ message ));
Fclose ($ fp );
Unlink ($ indexFileLock); // unlock
?>
Read replacement code
$ IndexFile = 'index. database ';
$ IndexFileLock = $ indexFile. 'lock ';
While (file_exists ($ indexFileLock) $ temp; // checks whether the lock has been applied.
Fclose (fopen ($ indexFileLock, 'w'); // If not, the system enters and locks to avoid visiting conflicts.
$ Ary = file ($ indexFile );
Unlink ($ indexfileLock); // unlock
For ($ I = 0; $ I $ TempAry = explode ('|', $ ary [$ I]);
Echo ('name: '. $ tempAry [0]);
Echo ('***:'. $ tempAry );
Echo ('saveposite: ', $ tempAry [3]); // You can read the message content from this address.
}
?> Through the above, you can easily solve common web applications, such as chat rooms, BBS forums, bookmarks, and so on.
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