简单的用php+txt做的论坛代码_PHP
程序员文章站
2022-04-08 16:55:38
...
在没有数据库的支持的情况下,用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。一个提交源码
$address = getenv("REMOTE_ADDR");
$filename = "$DOCUMENT_ROOT/view.txt";
$nam = stripslashes($name);
$topi = stripslashes($topic);
//echo $email;
$emai = stripslashes($email);
$messag = stripslashes($message);
$cnt = "
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 = "
?>
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>/font>/td>
/td>
/tr>
/table>
/center> /body>
/html>
3.查看源码
$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">
首先是制作一个输入界面!
!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。一个提交源码
$address = getenv("REMOTE_ADDR");
$filename = "$DOCUMENT_ROOT/view.txt";
$nam = stripslashes($name);
$topi = stripslashes($topic);
//echo $email;
$emai = stripslashes($email);
$messag = stripslashes($message);
$cnt = "
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 = "
Data Input complete
";?>
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">
p>a href="view.php">View Entries Here!!!/a>/p>
echo "$cnt";
echo "$cnt2";
echo "$cnt3";
echo "$cnt4";
echo "$cnt5" ?>
?/BLOCKQUOTE>/font>/td>
/td>
/tr>
/table>
/center> /body>
/html>
3.查看源码
$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">