PHP Text Message board--code sharing
index.php (Home)
U.S.-Japan Exchange message Board www.hnzyxok.com
Add message
doaddliuyan.php (Add message)
U.S.-Japan Exchange message Board www.hnzyxok.com
Add message
Perform message add action
1. Get the message you want to add and fill in additional information (IP address, add time)
$title = $_post["title"]; Get the message title
$author = $_post["Author"]; Get the message to the person
$content = $_post["Content"]; Message content
$ip = $_server["REMOTE_ADDR"]; IP Address
$addtime = time (); Add Time (timestamp)
2. Assembling (assembling) message information
$ly = "{$title}##{$author}##{$content}##{$ip}##{$addtime}@@@";
Echo $ly;
3. Append the message to the Liuyan.txt file
$info = file_get_contents ("Liuyan.txt");//Get all previous messages in the latest value stitching to write
File_put_contents ("Liuyan.txt", $info. $ly);//change function is overwrite write
4. Output Message Success!
echo "The message was successful! Thank you! ";
?>
menu.php (nav bar)
U.S.-Japan Exchange message Board www.hnzyxok.com
Add Message |
View Message
delete.php (Delete message)
U.S.-Japan Exchange message Board www.hnzyxok.com
Delete message
Executes a message that deletes the specified ID.
1. Get the ID number of the message you want to delete
$id = $_get["id"];
2. Get message information from message liuyan.txt information file
$info = file_get_contents ("Liuyan.txt");
3. Split the message into a message array with the @@@ 的
$lylist = Explode ("@@@", $info);
4. Use unset to delete a message with the specified ID
Unset ($lylist [$id]);
5. Restore the message to a string, and write back to the message file: Liuyan.txt
$ninfo = Implode ("@@@", $lylist);
File_put_contents ("Liuyan.txt", $ninfo);
6.
echo "deleted successfully! ";
?>
show.php (Show message)
U.S.-Japan Exchange message Board www.hnzyxok.com
View Message
Message title |
Message Person |
Message Content |
IP Address |
Message Time |
Operation |
Get message information, parse and output to the table. 1. Get message information from message liuyan.txt information file $info = file_get_contents ("Liuyan.txt"); 2. Take out the last three @@@ 符号 $info = RTrim ($info, "@"); if (strlen ($info) >8) {//3. Split the message with the @@@ 符号 as one article. (The message information is broken into the message array by the @@@ 的) $lylist = Explode ("@@@ 的, $info); Var_dump ($lylist); 4. Iterate through the message array and parse each message again foreach ($lylist as $k + $v) {$ly = Explode ("# #", $v);//Send each message message with # #号拆分成每个留言字段 echo "
"; echo "
{$ly [0]} | "; echo "
{$ly [1]} | "; echo "
{$ly [2]} | "; echo "
{$ly [3]} | "; echo "
". Date (" Y-m-d h:i:s ", $ly [4]+8*3600)." | "; echo "
Delete | "; echo "
"; echo $v. ""; }//}?>