简单新闻新闻公告!!(php,不用数据库)
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://240420643.blog.51cto.com/350567/103206 |
分3个页面:news_add.php,news_list.php,config.php config.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <? $adminpsd="zkl"; $newsbook="newsbook.txt"; $refreshbook="refreshbook.txt"; $pic="banzhu.jpg"; $line_max=5; ?> </body> </html> news_list.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <? require("config.php"); $line_array=file($newsbook); $linenum=count($line_array); if(@$table!=1) { ?> <table bgcolor="#00FF66" align="center" width="100%"> <tr> <td width="20"> </td> <td></td> </tr> <? } $i=0; while($i<$linenum&&$i<$line_max) { $line="$line_array[$i]\n"; echo "$line"; $i++; } if(@$table!=1) { ?> </table> <? } ?> <a href="news_add.php">添加新闻</a> </body> </html> news_add.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <? if(@!$_POST['action']) { ?> <form action="news_add.php" method="post"> <table width="100%"> <tr> <td width="15" align="left" > <table align="center" width="950"> <tr align="left"> <td align="left"> 呢称:<input type="text" name="person"> </td> </tr> </table> </td> </tr> <tr> <td width="100" align="center" height="100" > 新闻内容:<br><textarea name="title" rows="20" cols="120"></textarea> </td> </tr> <tr> <td align="center"> <input type="hidden" name="action" value="1"> <input type="submit" value="提交"><input type="reset" value="重写"> </td> </tr> </table> </form> <? } else { require("config.php"); if($_POST['person']!=$adminpsd) { echo "密码错误!<br>"; exit; } $title=ereg_replace("\r\n",'<br>',$_POST['title']); $addline="<tr><td align=\"top\"><img border=\"0\" src=\"$pic\" width=\"20\" height=\"20\"></td><td>$title</td></tr>"; if(!file_exists($refreshbook)) { $f=fopen("$refreshbook","w"); fclose($f); } if(!file_exists($newsbook)) { $f=fopen("$newsbook","w"); fclose($f); } $f=fopen("$refreshbook","r"); $line_has1=fread($f,filesize("$refreshbook")); fclose($f); if($addline==$line_has1) { echo "数据已经登录,请不要刷新!!<br>"; echo "<a href=\"news_list.php\">看新闻</a>"; exit; } else { $f=fopen("$refreshbook","w"); fwrite($f,"$addline"); fclose($f); } $f=fopen("$newsbook","r"); $line_has=fread($f,filesize("$newsbook")); fclose($f); $f=fopen("$newsbook","w"); $addline.=$line_has; fwrite($f,"$addline\n"); fclose($f); echo "录入完成,谢谢!!<br>"; echo "<a href=\"news_list.php\">看新闻</a>"; exit; } ?> <a href="news_list.php">看新闻</a> </body> </html> 本文出自 “雷克地沟” 博客,请务必保留此出处http://240420643.blog.51cto.com/350567/103206 本文出自 51CTO.COM技术博客 |


240420643
博客统计信息
热门文章
最新评论
友情链接