PHP text message board source code
PHP text message board-code sharing
Index. php (home page)
US-Japan message board www.hnzyxok.com
Add message
DoAddLiuYan. php (add comments)
US-Japan message board www.hnzyxok.com
Add message
// Add the message
// 1. obtain the message to be added and add other auxiliary information (IP address, add time)
$ Title = $ _ POST ["title"]; // Obtain the message title
$ Author = $ _ POST ["author"]; // get the message recipient
$ Content = $ _ POST ["content"]; // message content
$ Ip = $ _ SERVER ["REMOTE_ADDR"]; // ip address
$ Addtime = time (); // add time (timestamp)
// 2. assembly (assembly) message
$ Ly = "{$ title }##{$ author }##{$ content }#{$ ip }##{$ addtime }@@@";
// Echo $ ly;
// 3.add the message information to the liuyan.txt file
$ Info = file_get_contents ("liuyan.txt"); // Obtain all previous messages and write them in the latest value.
File_put_contents ("liuyan.txt", $ info. $ ly); // rewrite the function to overwrite
// 4. The message is successfully output!
Echo "message successful! Thank you! ";
?>
Menu. php (navigation bar)
US-Japan message board www.hnzyxok.com
Add a message |
View messages
Delete. php (delete message)
US-Japan message board www.hnzyxok.com
Delete message
// Delete the message of the specified id.
// 1. obtain the ID number of the message to be deleted
$ Id = $ _ GET ["id"];
// 2.obtain the message information from the message liuyan.txt file.
$ Info = file_get_contents ("liuyan.txt ");
// 3. split the message with the symbol @ into a message array
$ Lylist = explode ("@", $ info );
// 4. use unset to delete the message with the specified id
Unset ($ lylist [$ id]);
// 5. restore the message as a string and write back the message file: liuyan.txt
$ Ninfo = implode ("@", $ lylist );
File_put_contents ("liuyan.txt", $ ninfo );
// 6.
Echo "deleted successfully! ";
?>
Show. php (show messages)
US-Japan message board www.hnzyxok.com
Script
// Define the js code to be deleted.
Function dodel (id ){
If (confirm ("Are you sure you want to delete it? ")){
Window. location = 'Del. php? Id = '+ id;
}
}
Script
View messages
| Message title |
Contact |
Message content |
IP address |
Message time |
Operation |
// Obtain the message and parse it and output it to the table.// 1.obtain the message information from the message liuyan.txt file.$ Info = file_get_contents ("liuyan.txt "); // 2. retrieve the last three symbols of the message content$ Info = rtrim ($ info ,"@");If (strlen ($ info)> 8 ){// 3. split the message with the @ symbol as one.// (Split the message with the symbol @ into a message array)$ Lylist = explode ("@", $ info );// Var_dump ($ lylist );// 4. traverse the message array and parse each message againForeach ($ lylist as $ k => $ v ){$ Ly = explode ("#", $ v); // splits each message into each field #Echo"
";Echo"
| {$ Ly [0]} | ";Echo"
{$ Ly [1]} | ";Echo"
{$ Ly [2]} | ";Echo"
{$ Ly [3]} | ";Echo"
". Date (" Y-m-d H: I: s ", $ ly [4] + 8x3600 )." | ";Echo"
Delete | ";Echo"
";// Echo $ v ."";}//}?>