PHP简单留言本

INDEX.PHP
结构:PHP+TXT
文件:Index.php、Add.php
由于空间不支持数据库,
所以只能用文本保存数据了,
特点是
1、功能简单,只有两个文件index.php和add.php;
2、不用数据库,上传后就可以使用。
但只是个留言本的雏形,还有很多功能需要完善,不过可以先熟悉PHP的语法什么的。: )
<HTML>
<HEAD><TITLE>songzi book</TITLE>
<BODY >
<style type="text/css">
<!--
body,table { font-family: "宋体"; font-size: 12px;background:#DCDCDC;}
table
{
table-layout:fixed;
word-break:break-all;
word-wrap:break-word;
}
-->
</style>
<center>
<h2>songzi book</h2>
<hr>
<?
//分页
$num1="8";
$num1=$num1;
if($page==""){$page=1;}else{$page=$page;}
$num2=$num1*$page;
$num4=$page-1;
$num4=$num1*$num4;
$book="book.txt";
$garray = file($book);
$cog=count($garray);
if($cog<=$num2){$cog=$cog;}else{$cog=$num2;}
for($i=$num4;$i<$cog;$i++){
$larray = explode("|",$garray[$i]);
$name=$larray[0];
$cont=$larray[1];
$date=$larray[2];
echo <<<EOD
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20%" >昵&nbsp;&nbsp;&nbsp;&nbsp;称: </td>
<td width="42%" bgcolor="#F7F7F7">$name</td>
<td width="38%" bgcolor="#F7F7F7"><div align="right">$date</div></td>
</tr>
<tr>
<td width="20%">留言内容:</td>
<td colspan="2" bgcolor="#EBEBEB" onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='' &#10; ">$cont</td>
</tr>
<tr>
<td height="20%" colspan="3 ">&nbsp; </td>
</tr>
</table>
EOD;
}
?>
<hr>
<TABLE width="80%" border=0>
<TR> <TD align=right>
<?
$cog1=count($garray);
$num3=$cog1/$num1;
for($p=1;$p<$num3;$p++){
print ("<B><A
href=index.php?page=$p>$p</A></B> ");
}
print ("<B><A
href=index.php?page=$p>$p</A></B> ");
?>
</TD></TR></TBODY></TABLE>
<form action="add.php" method="post">
昵称:<input type="text" size="20" name="name"><br><br>
留言内容:<br>
<TEXTAREA name=cont rows=8 cols=46></TEXTAREA><br><br>
<input type="submit" value="提交">
<form>
</BODY></HTML>

<?php
if($name=="")
{
echo "<center><br><br><br><br><br><br> 忘记填名字啦?<P>";
echo '<meta HTTP-EQUIV="REFRESH" CONTENT="1;URL=index.php">';
exit();
}
if($cont=="")
{
echo "<center><br><br><br><br><br><br> 请填写内容!<P>";
echo '<meta HTTP-EQUIV="REFRESH" CONTENT="1.8;URL=index.php">';
exit();
}
$total=strlen($name.$cont);
if ($total>600)
{
echo "<center><br><br><br><br><br><br> 字数超过限制!<P>";
echo '<meta HTTP-EQUIV="REFRESH" CONTENT="1.8;URL=index.php">';
exit();
}
?>
<?php
// 写入文件
$book="book.txt";
$g = file($book);
$cog=count($garray);
$larray = explode("|",$garray[0]);
$id=$larray[0]+1;
$cont=str_replace("\n","<br>",$cont);
$date=date("Y-m-d H:i:s");
$xian=array($name,$cont,$date);
$newguest = implode("|", $xian)."|\r\n";
$f = fopen($book,"r+");
$msg = fread($f,filesize($book));
fclose($f);
$fp=@fopen($book,"w+");
@fwrite($fp,$newguest.$msg);
@fclose($fp);
echo '<meta HTTP-EQUIV="REFRESH" CONTENT="0;URL=index.php">';
exit;
?>

评论列表

此文章还没有评论。