当前位置: 首页 > 图文教程 > 网络编程 > PHP > 基于文本的访客签到簿

PHP
PHP新手总结的PHP基础知识
php实现gb2312和unicode间编码转换
用php语言实现数据库连接详细代码介绍
详细解析 PHP 向 MySQL 发送数据过程
利用PHP V5开发多任务应用程序
详细讲解PHP中缓存技术的应用
php escapeshellcmd多字节编码漏洞
《PHP设计模式介绍》导言
《PHP设计模式介绍》第一章 编程惯用法
《PHP设计模式介绍》第二章 值对象模式
《PHP设计模式介绍》第三章 工厂模式
《PHP设计模式介绍》第四章 单件模式
《PHP设计模式介绍》第五章 注册模式
《PHP设计模式介绍》第六章 伪对象模式
《PHP设计模式介绍》第七章 策略模式
《PHP设计模式介绍》第八章 迭代器模式
《PHP设计模式介绍》第九章 观测模式
《PHP设计模式介绍》第十章 规范模式
《PHP设计模式介绍》第十一章 代理模式
《PHP设计模式介绍》第十二章 装饰器模式

PHP 中的 基于文本的访客签到簿


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 243 ::
收藏到网摘: n/a

一个很偶然的机会,在网上看到了有人用PHP+MYSQL作了一个访客签到簿, 当时觉得很有用处所以自己也很 想搞一个。但是用MYSQL觉得有点在材小用,所以就搞了一个基于文本的访客签到簿。其功能与我在网上看 到的用MYSQL作的差不多,在这里我将其源码公布,希望它对放大网友学习PHP有所帮助。限于本人的水平, 其中定有BUG,还希望朋友发现了不要忘告诉我一下。本签到簿由要两个文件组成:一个是存放签到信息的sign.txt文件, 该文件可以由NOTEPAD来创建;第二个 是处理信息的sign.php文件。在斑竹园的主页<http://bamboo.oso.com.cn>有它的演示,欢迎去看看。下面
就是sign.php的源代码:
sign.php
if(isset($name)&&isset($msg)){
$name=ltrim($name);
$t=date(y年m月d日);
$dat="[".$t."]";
$msg=ltrim($msg);
$name=trim($name);
$msg=trim($msg);
$pristr=$name."  ".$dat." ".$msg."\n";
$f=fopen("sign.txt","a");
fwrite($f,$pristr);
fclose($f);
}
$file=file("sign.txt");
if(!isset($pagenum)){
$pagenum=1;
}
$lesssign=0;
$num=count($file);
$dispnumed=6*($pagenum-1);
$dispnumbeg=$num-$dispnumed;
$artnumeof1=6*$pagenum;
$isdispnum=$num-$artnumeof1;
if($isdispnum<=0){
$dispnumeof=1;
$lesssign=1;
}
else{
$dispnumeof=$isdispnum+1;
}
$sign=0;
$pagec=0;
for($icount=0;($icount<$num)&&($sign==0);$icount+=6){
for($i=0;$i<=6;$i++){
if(($icount*6+$i)==$num){
$sign=1;
}
}
$pagec++;
}
$pagecount=$pagec;
echo"<table width=100% cellspacing=3>";
$fuhao="◇ ";
$color=e9eae9;
$iscolor=0;
$lessnum=5;
echo"<tr><td bgcolor=00ff00 align=center>";
echo"斑竹园签到簿";
echo"</td></tr>";
for($i=$dispnumbeg;$i>=$dispnumeof;$i--){
$linknum=$num-$i;
$lessnum--;
$stringmsg1=$file[($i-1)];
$stringmsg2=strrev($stringmsg1);
$stringmsg3=strstr($stringmsg2,"psbn");
$stringmsg=strrev($stringmsg3);
$stringlink=strstr($file[($i-1)],"http");
$dispvar=$fuhao.$stringmsg;
echo"<tr><td bgcolor=$color>";
echo$dispvar;
echo "<img src=gif/home3.gif>";
echo"<a href=$stringlink>";
echo$stringlink;
echo"</a>";
echo"</td></tr>";
if($iscolor==0){
$color=ffffff;
$iscolor=1;
}
else{
$color=e9eae9;
$iscolor=0;
}
}
if($lesssign==1){
for($iless=$lessnum;$iless>0;$iless--){
echo"<tr bgcolor=$color><td>";
echo $fuhao."<br>\n";
echo"</td></tr>";
if($iscolor==0){
$color=ffffff;
$iscolor=1;
}
else{
$color=e9eae9;
$iscolor=0;
}
}
}
echo"<tr>";
echo"<form action=index.php method=post>";
echo"<td>";
echo"称呼:";
echo"<input name=name size=10 maxlength=20>";
echo"地址:";
echo"<input name=msg size=20 maxlength=60 value=http://>";
echo"<input type=submit name=submit value=签到>";
echo"</td>";
echo"</form>";
echo"</tr>";
echo"</table>";
?>