在没有数据库的支持的情况下,用txt和php可以做论坛吗?当然可以了。是不是很复杂阿,也不是,非常的简单。下面就给出这个例子,供大家参考! 首先是制作一个输入界面! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>PHP4 Input Script</TITLE> <META http-equiv=content-type content=text/html;charset=iso-8859-1> <META content="Microsoft FrontPage 4.0" name=GENERATOR></HEAD> <BODY> <TABLE height=495 cellSpacing=0 cellPadding=0 width=578 border=0 cool gridx="16" showgridx usegridx gridy="16" showgridy usegridy> <TBODY> <TR height=64> <TD width=20 height=29><SPACER type="block" width="1" height="64"></TD> <TD width=20 height=29></TD> <TD width=24 height=29></TD> <TD width=14 height=29></TD> <TD width=14 height=29></TD> <TD width=28 height=29></TD> <TD vAlign=top align=left width=203 colSpan=4 height=29 xpos="128" content csheight="32"> <H3 align="center">Forum: title goes here</H3></TD> <TD vAlign=top align=left width=103 height=29 xpos="128" content csheight="32"> </TD> <TD width=128 height=29></TD> </TR> <TR height=48> <TD width=20 height=29><SPACER type="block" width="1" height="48"></TD> <TD width=20 height=7></TD> <TD width=24 height=7></TD> <TD width=14 height=7></TD> <TD vAlign=top align=left width=46 colSpan=4 height=7 xpos="96" content csheight="32">Name:</TD> <TD vAlign=top align=left width=199 colSpan=2 height=7 xpos="144"><INPUT size=24 name=name></TD> <TD vAlign=top align=left width=101 height=7 xpos="144"></TD> <TD width=128 height=7></TD> </TR> <tr> <TD width=20 height=31></TD> <TD width=20 height=31></TD> <TD width=24 height=31></TD> <TD vAlign=top align=left width=14 height=31 xpos="96" content csheight="32"></TD> <TD vAlign=top align=left width=44 colSpan=3 height=31 xpos="96" content csheight="32">Email:</TD> <TD vAlign=top align=left width=201 colSpan=3 height=31 xpos="144"><INPUT size=24 name=email></TD> <TD width=101 height=31></TD> <TD width=136 height=31></TD> </tr> <TR height=32> <TD width=20 height=26><SPACER type="block" width="1" height="32"></TD> <TD width=20 height=26></TD> <TD width=24 height=26></TD> <TD width=14 height=26></TD> <TD vAlign=top align=left width=45 colSpan=4 height=26 xpos="96" content csheight="32">Topic:</TD> <TD vAlign=top align=left width=199 colSpan=2 height=26 xpos="144"><INPUT size=24 name=topic></TD> <TD vAlign=top align=left width=101 height=26 xpos="144"></TD> <TD width=128 height=26></TD> </TR> <TR height=29> <TD width=20 height=19><SPACER type="block" width="1" height="29"></TD> <TD width=20 height=19></TD> <TD width=24 height=19></TD> <TD vAlign=top align=left width=62 colSpan=6 height=19 xpos="80" content csheight="29">Message:</TD> <TD width=199 height=19></TD> <TD width=101 height=19></TD> <TD width=128 height=19></TD> </TR> <TR height=243> <TD width=20 height=243><SPACER type="block" width="1" height="243"></TD> <TD width=20 height=243></TD> <TD width=24 height=243></TD> <TD vAlign=top align=left width=496 colSpan=9 height=243 xpos="80"> <TEXTAREA name=message rows=13 wrap=virtual cols=40></TEXTAREA></TD> </TR> <TR height=157> <TD width=20 height=23><SPACER type="block" width="1" height="157"></TD> <TD width=20 height=23></TD> <TD width=24 height=23></TD> <TD width=14 height=23></TD> <TD width=14 height=23></TD> <TD vAlign=top align=left width=231 colSpan=5 height=23 xpos="112"> <INPUT type=reset value=Clear></TD> <TD vAlign=top align=left width=101 height=23 xpos="288"> <INPUT type=submit value=Post name=submitButtonName></TD> <TD width=128 height=23></TD> </TR> </TBODY></TABLE></BODY></HTML> 2。一个提交源码 <?php $address = getenv("REMOTE_ADDR"); $filename = "$DOCUMENT_ROOT/view.txt"; $nam = stripslashes($name); $topi = stripslashes($topic); //echo $email; $emai = stripslashes($email); $messag = stripslashes($message); $cnt = "<hr> Name: $nam n"; $cnt2 = "Topic: $topi n"; $cnt3 = "Message: $messag n"; $cnt4 = "IP: $address nn"; $cnt5 = "EMail address: $emai n"; $filed = @fopen($filename, "a+"); @fwrite($filed, "$cnt $cnt2 $cnt3 $cnt4 $cnt5"); fclose($filed); $msg = "<p>Data Input complete</P>"; ?> <html> <head> <title>Forum Posted</title> </head> <body> <center> <table width="90%"> <TBODY> <tr><td bgcolor="#aeaeae"><FONT face=Tahoma size=2><STRONG>~BBS~</STRONG></FONT></td></tr> <tr><td bgcolor="#c0c0c0"><font size="2" face="tahoma" color="#000000"> <BLOCKQUOTE> <?php echo "You entered:"; echo "$cnt"; echo "$cnt2"; echo "$cnt3"; echo "$cnt4"; echo "$cnt5" ?> <p><a href="view.php">View Entries Here!!!</a></p> ?/BLOCKQUOTE></font></td> </td> </tr> </table> </center> </body> </html> 3.查看源码 <?php $filename = "$DOCUMENT_ROOT/view.txt"; $whattoread = @fopen($filename, "r"); $file_cnt = fread($whattoread, filesize($filename)); $msg = "$file_cnt"; fclose($whattoread); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>BBS or Forum title here</title> </head> <body> <DIV align=center> <TABLE style="HEIGHT: 113px; WIDTH: 420px"> <TR> <TD bgcolor="#9999cc"></TD> <TD bgcolor="#9999cc"></TD> <TD bgcolor="#9999cc"></TD></TR> <TR> <TD bgcolor="#9999cc"></TD> <TD bgcolor="#9999cc" height=16> <P align=center>BBS or Forum Title here</P> </TD> <TD bgcolor="#9999cc"></TD></TR> <TR> <TD bgcolor="#9999cc"></TD> <TD><?php echo "$msg" ?></TD> <TD bgcolor="#9999cc"></TD></TR> <TR> <TD bgcolor="#9999cc"></TD> <TD bgcolor="#9999cc"></TD> <TD bgcolor="#9999cc"></TD></TR></TABLE></DIV> </body> </html> 这么样阿,就这么简单,但我还是有点疑问,这样的反复操作磁盘,对系统有没有影响,另外,html页面可以比这个复杂,但精华在不过如此! 希望有兴趣的朋友可以在自己的论坛上试一下,看看效果如何! 原作者:Daniel 来源:www.phpbuilder.c |