Generally, no mysql support is provided for personal free homepage space, that is, it is also very demanding, so it is important to find a good alternative! PHP file processing is very powerful, so it can be replaced by file access! (When there is no database, all files are organized! Haha !), One of the data items is separated by special symbols. generally, personal free homepage space does not provide mysql support, that is, it is also very demanding, so it is important to find a good alternative!
PHP file processing is very powerful, so it 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!
In fact, the database concept can still be used here! Like the database index!
Therefore, you must create an index file first! (This is not true)
Let's talk about it in the message book:
The main files are:
Index. database
Its structure is as follows:
Name of the contact person | gender of the contact person | message time | location of the message content | 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 data conflicts between multiple users, you need to apply a lock (also implemented using files)
The following code is written:
// The following parameters must be input:
// Name of the contact $ name
// Gender of the message recipient $ sex
// Message time $ time
// Location where the message content is stored $ savePosite
$ IndexFile = "index. database ";
$ IndexFileLock = $ indexFile. "Lock ";
$ Message = $ name. "| ". $ sex. "| ". $ 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, enter and lock to avoid access conflicts.
$ Fp = fopen ($ indexFile, "");
Fputs ($ message, strlen ($ message ));
Fclose ($ fp );
Unlink ($ indexFileLock); // unlock
?>
Read 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, enter and lock to avoid access conflicts.
$ Ary = file ($ indexFile );
Unlink ($ indexfileLock); // unlock
For ($ I = 0; $ I $ TempAry = explode ("|", $ ary [$ I]);
Echo ("name:". $ tempAry [0]);
Echo ("sex:". $ tempAry [1]);
Echo ("sex:". $ tempAry [2]);
Echo ("savePosite:", $ tempAry [3]); // You can read the message content from this address.
}
?>
Through the above, you can easily solve commonly used Web pages, such as chat rooms, BBS forums, bookmarks, and so on.
If that prawn has a better solution, please enlighten me! Thank you!
My Homepage: feiyschool.51.net
QQ: 23072155
Email: feiyhy@sina.com