php无需数据库的网站留言板程序
php教程无需数据库教程的网站留言板程序
<form name="form1" method="post" action="">
<label>
<input type="text" name="title">
标题<br>
<br>
</label>
<label>
<textarea name="content" cols="50" rows="10"></textarea>
</label>
内容
<p>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</p>
</form>
<?
if( $_POST )
{
$file='list.txt';
$array = $_POST;
$content ="标题:".$array['title'].' 内容:'.$array['content'].chr(13);
if( file_exists( $file ) )
{
add_write($content);
echo '保存成功';
}
else
{
null_write($content);
}
}
function null_write($new)
{
global $file;
$f=fopen($file,"w");
flock($f,LOCK_EX);
fputs($f,$new);
fclose($f);
}
// 添加数据记录到文件末端
function add_write($new) {
global $file;
$f=fopen($file,"a");
flock($f,LOCK_EX);
fputs($f,$new);
fclose($f);
}
/*
fopen 写文件
flock 锁定文件,防止同时多人操作
fputs 写文件,把内容写入文件
fclose 关闭文件
注明:本站原创转载注明来源www.zzzyk.com
*/
?>
补充:Php教程,Php入门