PHP text-style message board source code

Source: Internet
Author: User
Tags add time

PHP text Message Board--code sharing


index.php (Home)

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>U.S.-Japan Exchange message Board www.hnzyxok.com</title>
<body>
<center>
<?php include ("menu.php"); Import the navigation bar of a Web site?>

<form action= "doadd.php" method= "POST" >
<table width= "380" border= "0" cellpadding= "4" >
<tr>
&LT;TD align= "right" > title:</td>
<td><input type= "text" name= "title"/></td>
</tr>
<tr>
&LT;TD align= "Right" > Message:</td>
<td><input type= "text" name= "author"/></td>
</tr>
<tr>
&LT;TD align= "right" valign= "top" > Message content:</td>
<td><textarea name= "Content" rows= "5" cols= "></textarea></td><!--5 rows, 30 columns--
</tr>
<tr>
&LT;TD colspan= "2" align= "Center" >
<input type= "Submit" value= "Submission"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type= "reset" value= "reset"/>
</td>

</tr>
</table>
</form>
</center>
</body>


doaddliuyan.php (Add message)

<title>U.S.-Japan Exchange message Board www.hnzyxok.com</title>
<body>
<center>
<?php include ("menu.php"); Import the navigation bar of a Web site?>

<?php
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! ";
?>
</center>
</body>



menu.php (nav bar)
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
U.S.-Japan Exchange message Board www.hnzyxok.com
<a href= "index.php" > Add a Message </a> |
<a href= "show.php" > View message </a>


delete.php (Delete message)

<title>U.S.-Japan Exchange message Board www.hnzyxok.com</title>
<body>
<center>
<?php include ("menu.php"); Import the navigation bar of a Web site?>

<?php
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! ";
?>
</table>
</center>
</body>


show.php (Show message)

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>U.S.-Japan Exchange message Board www.hnzyxok.com</title>
<script>
Define a JS code that asks if you want to delete it.
function Dodel (ID) {
if (Confirm ("OK to delete?") ")){
window.location= ' del.php?id= ' +id;
}
}
</script>
<body>
<center>
<?php include ("menu.php"); Import the navigation bar of a Web site?>

<table border= "1" width= ">"
<tr>
<th> Message title </th>
<th> Message Person </th>
<th> Message Content </th>
<th>ip Address </th>
<th> Message Time </th>
<th> Operations </th>
</tr>
<?php
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. Remove the last three @@@ 符号 from the message content
$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);//leave each message message in # #号拆分成每个留言字段
echo "<tr>";
echo "<td>{$ly [0]}</td>";
echo "<td>{$ly [1]}</td>";
echo "<td>{$ly [2]}</td>";
echo "<td>{$ly [3]}</td>";
echo "<td>". Date ("Y-m-d h:i:s", $ly [4]+8*3600). </td> ";
echo "<td><a href= ' Javascript:dodel ({$k}) ' > Delete </a></td>";
echo "</tr>";
echo $v. " <br/> ";
}
//
}
?>
</table>
</center>
</body>

PHP text-style message board source code

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.