设为首页收藏本站订阅更新

无忧脚本

 找回密码
 加入无忧

QQ登录

只需一步,快速开始

搜索
查看: 5090|回复: 3

[原创] PHP入门作 单文件微博

[复制链接]
发表于 2010-12-7 15:38:56 | 显示全部楼层 |阅读模式
Js10单文件php个人微博

运行环境:PHP5+;
支持数据库:MS的3种数据库 Access Excel DBase
初始密码: admin

这是我第一个PHP单文件作品,支持基本的评论和管理功能
支持URL的识别,评论验证功能

本程序上传就可使用,自动生成XLS数据库
也可使用其他数据库,替换DataBase为Access,创建对应DataFile名称的.MDB文件即可
替换DataBase为DBase,创建对应DataFile名称的【文件夹】即可;

[php]<?php
/*
PHP单文件个人微博
请在PHP5.0+环境下运行
*/
$KaiShi=microtime();
header("Content-Type: text/html; charset=gb2312");
//################################   建议手动设置
//数据库驱动 支持DBase ,Access ,Excel
$DataBase="Excel";                    //支持4种数据库,按上面输入
//数据库名称
$DataFile="Data.xls";                 //DBase和sql都不要有后缀
//如果使用sql或mysql服务器请设置该项
$sqlset="Server=localhost;Port=3306" ; //Server为服务器IP;Port为服务器端口(sql默认端口1433,mysql默认为3306,3307)
$sqlUser="UID=root;PWD=root" ;            //UID为服务器用户名PWD为服务器密码
//站点Session设置
$SessionSite="site";
$PageSize=6;//默认每页条数
//##########################################
session_start();
if(@phpversion()<5)die("PHP版本过低,需要php5以上");
$FileName=@$_SERVER["SCRIPT_NAME"];  //文件路径
$MoKuai=@$_GET["mode"];
$QuanXian=@$_SESSION[$SiteSession."_Access"];      //权限判断
$db=@$_SERVER["DOCUMENT_ROOT"]."\\".$DataFile;
$conn=new COM("ADODB.Connection");
$rs=@new COM("ADODB.RecordSet");
define("IP",$_SERVER["REMOTE_ADDR"]);
//############ 数据库开始
Switch($DataBase){
case "Access":
case "mdb":
$connstr="Driver={Microsoft Access Driver (*.mdb)};DBQ=".RealPath($DataFile).";";
$Text="memo";
$Int="double";
break;
case "dbase":
case"DBase":
$connstr="Driver={Microsoft DBase Driver (*.dbf)};DBQ=".$db.";";
$Text="memo";
$Int="double";
break;
default:
$connstr="Driver={Microsoft Excel Driver (*.xls)};DBQ=".$db.";ReadOnly=0;";
$Text="memo";
$Int="int";
break;
}
$conn->Open($connstr);
Try{
$sql="select * from copyright";
$rs->Open($sql,$conn);
$WangZhan=$rs["spacename"]."";
$WangZhi=$rs["spaceurl"]."";
$Info=$rs["spaceinfo"]."";
$YanZhen="".$rs[5]->value;
$YongHu=$rs[0]."";
$MiMa=$rs[1]."";
$rs->Close();
}
Catch(Exception $Err)
{
/***********    数据生成     **************/
$sql="create table article(BH int,NeiRong $Text,RiQi $Int,ShanChu bit)";
$conn->Execute($sql);
$sql="create table comment(BH int,ZuoZhe varchar(10),NeiRong $Text,RiQi varchar(40),IP varchar(40),FenLei $Int,YanZhen bit,ShanChu bit)";
$conn->Execute($sql);
$sql="create table copyright(username varchar(20),password varchar(32),spacename varchar(40),spaceurl varchar(254),spaceinfo $Text,YanZhen bit)";
$conn->Execute($sql);
$sql="Insert into copyright values('admin','".md5("admin")."','Js10的微博','http://www.js10.com/','欢迎光临我的微生活!',0)";
$conn->Execute($sql);
sleep(2);
Die("数据库生成成功!");
}
?>
<META http-equiv="Content-Type" content="text/html; charset=gb2312" />
<META name="Keywords" content="<?=$WangZhan?>">
<TITLE><?=$WangZhan?> - <?=$WangZhi?></TITLE>
<STYLE>
p,form,li{margin:0;}
div{WORD-BREAK:break-all;}
html,body{margin:15px;padding:0;font:normal 12px tahoma;background:#ECF0F9;}
input{border:3px solid #E2E9F6;}
#main{width:100%;}
.biaoti{font:normal 18px 仿宋;margin:2px;padding:3px;color:#549C00;}
.info{color:#999;padding:3px}
#list a:hover,#list a{color:#4F81BD;}
#daohang{margin:7px;}
#daohang a:hover,#daohang a{padding:3px;margin:5px;color:#4F81BD;}
.txt{height:80px;}
#list,TEXTAREA{width:100%;background:#FBFCFE;border:3px solid #E2E9F6;padding:10px;}
.memo{font-size:14px;border-bottom:1px dashed #E2E9F6;width:95%;margin:5px;padding:5px;Color:#333}
#set .left{float:left;font-size:13px;color:#888}
#set .right{float:right;font-size:13px;}
#re{font-size:11px;color:#888;padding:3px;margin:3px;}
#re a,#re a:hover{color:#888}
.page{border:1px solid #E2E9F6;padding:3px;margin:2px;background:white;}
#pages a:hover,#pages a{color:#4F81BD;}
#pages{margin:5px;padding:5px}
#redit textarea{width:400px;height:80px}
</STYLE>
<BODY>
<DIV id="main">
<DIV id="header">
<SPAN class="biaoti"><?=$WangZhan?></SPAN>
<SPAN class="info"><?=$Info?></SPAN><BR/>
<DIV id="daohang">
<A href="<?=$FileName?>">首页</A>
<?if($QuanXian=="Admin"){?>
<A href="<?=$FileName?>?mode=reply">评论管理</A>
<A href="<?=$FileName?>?mode=new">添加文章</A>
<A href="<?=$FileName?>?mode=user">帐号设置</A>
<A href="<?=$FileName?>?mode=set">系统设置</A>
<A href="<?=$FileName?>?mode=php">PHPINFO</A>
<?}
if($QuanXian!=="Admin"){
?><A href="<?=$FileName?>?mode=login">登录</A>
<?
}else{
?>
<A href="<?=$FileName?>?mode=out">退出</A>
<?
}
?>
<SPAN class=msg><?=$_GET["msg"].$_POST["Neirong"]->Length?></SPAN>
</DIV>
</DIV>
<?php
function variable($str){
$str=ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\" target=_blank>\\0</a>",$str);
return $str;
}
$NeiRong=$_POST["Neirong"];
$NeiRong=str_replace("'","''",$NeiRong);
$NeiRong=str_replace("<","&lt;",$NeiRong);     
$NeiRong=str_replace(">","&gt;",$NeiRong);
$NeiRong=str_replace("\r\n","<BR/>",$NeiRong);
if(strlen($NeiRong)>200){
header("Location:".$FileName."?msg=不要超过200字节",2);
die();
}
Switch($MoKuai){
case"out":
sleep(1);
Session_unset($Session."_Access");
echo"已经退出";
break;
case "php";
if($QuanXian=="Admin") phpinfo();
break;
case "login":
/***********    登录模块     **************/
if(!empty($_POST["DengLu"])){
if($_POST["Name"]==$YongHu&&MD5($_POST["Pass"])==$MiMa){
@$_SESSION[$SiteSession."_Access"]="Admin";
header("Location:".$FileName."?msg=登录成功",2);
}else{
Session_unset($Session."_Access");
echo “登录信息错误”;}
}
echo "<FORM action=$FileName?mode=login  method=post>";
echo "<INPUT name=Name size=14>";
echo "<INPUT name=Pass size=14 >";
echo "<INPUT type=submit  name=DengLu value=登录>";
echo "</FORM>";
break;
case "user":
/***********    用户设置     **************/
if($QuanXian=="Admin"){
if(!empty($_POST["TiJiao"])){
$conn->Execute("update copyright set username='".$_POST["Name"]."',password='".md5($_POST["Pass"])."'");
header("Location:".$FileName."?mode=user&msg=设置成功",2);
}
echo "<FORM action=$FileName?mode=user method=post>";
echo "<INPUT name=Name size=14 value=$YongHu>";
echo "<INPUT name=Pass size=14 >";
echo "<INPUT type=submit  name=TiJiao value=修改>";
echo "</FORM>";
}
break;
case "set":
/***********    系统设置     **************/
if($QuanXian=="Admin"){
if(!empty($_POST["TiJiao"])){
Try{
$yz=$_POST["yanzhen"]=="true"?1:0;
$conn->Execute("update copyright set spacename='".$_POST["webname"]."',spaceurl='".$_POST["Wangzhi"]."',spaceinfo='".$_POST["info"]."',yanzhen=$yz");
header("Location:".$FileName."?mode=set&msg=设置成功",2);
}catch(Exception $ERR){
print("<SCRPIT>window.alert('".$ERR->getMessage()."')</SCRIPT>");
}
}
echo"<FORM action=$FileName?mode=set method=post>";
echo "微博名称:<INPUT name=webname value=$WangZhan><BR>"
."网站地址:<INPUT name=Wangzhi value=$WangZhi><BR>"
."微博信息:<INPUT name=info value=$Info><BR>"
."";
if($YanZhen==1||$YanZhen=="Ture"){
echo"评论验证 <INPUT type=radio name=yanzhen checked value=true> 是 <INPUT type=radio name=yanzhen value=false> 否";
}else{
echo"评论验证 <INPUT type=radio name=yanzhen value=true> 是 <INPUT type=radio name=yanzhen checked value=false> 否";}
echo"<BR/><BR/><INPUT name=TiJiao type=submit value=设置></FORM>";
}
break;
case "edit":
/***********    编辑模块     **************/
if($QuanXian=="Admin"){
if(is_Int(intval($_GET["id"]))){
if(!empty($_POST["TiJiao"])&&!empty($_POST["Neirong"])){
$sql="update article set NeiRong='$NeiRong',riqi=".time()." where BH=".intval($_GET["id"]);
$conn->Execute($sql);
header("Location:".$FileName."?mode=edit&msg=修改成功",2);
DIE();
}
$rs->Open("select * from article where bh=".intval($_GET["id"]),$conn,1);
if(!$rs->eof){
$NeiRong=$rs["Neirong"]."";
$NeiRong=str_replace("<BR/>","\r\n",$NeiRong);
print"<FORM action=$FileName?mode=edit&id=".$_GET["id"]." method=post>"
."<TEXTAREA name=Neirong class=txt>".$NeiRong."</TEXTAREA><p>"
."<INPUT name=TiJiao type=submit value=修改>";
}else{
echo"没有找到这条数据";}
}
}
break;
case "new":
/***********    添加模块     **************/
if($QuanXian=="Admin"){
if(!empty($_POST["TiJiao"])&&!empty($_POST["Neirong"]))
{
global $rs,$conn;
$rset=$conn->Execute("select max(bh) from article");
$ArtCount=intval($rset->Fields[0]->value)+1;
$conn->Execute("insert into article values($ArtCount,'$NeiRong',".time().",0)");
header("Location:".$FileName."?mode=new&msg=添加成功",2);
DIE();
}
echo <<< HTML
<FORM action=$FileName?mode=new method=post>
<TEXTAREA name=Neirong class=txt></TEXTAREA><p>
<INPUT name=TiJiao type=submit value=添加>
HTML;
}
break;
Case "reply":
/***********    评论管理     **************/
global $rs;
if($QuanXian=="Admin"){
if($_GET["set"]=="del"&&is_int(intval($_GET["id"]))){
TRY{
$conn->Execute("delete from comment where bh=".intval($_GET["id"]));
header("Location:".$FileName."?mode=reply",2);
}Catch(Exception $E){
$conn->Execute("update comment set ShanChu=1 where bh=".intval($_GET["id"]));
header("Location:".$FileName."?mode=reply",2);}}
if($_GET["set"]=="yz"&&is_int(intval($_GET["id"]))){
$conn->Execute("update comment set yanzhen=1 where bh=".intval($_GET["id"]));
header("Location:".$FileName."?mode=reply",2);}
$sql="select * from comment where shanchu=0 order by riqi desc";
$rs->open($sql,$conn,1,3);
$rs->pagesize=7;
$page=intval($_GET["p"]);
if(!is_int($page)||$page<1) $page=1;
if($page>$rs->pagecount) $page=$rs->pagecount;
if($rs->eof){print("<BR>没有评论。<BR>");}
else{
$rs->absolutepage=$page;
for($C=0;$C<$rs->pagesize;$C++){
echo "<DIV id=list>";
if($rs["yanzhen"]->value!=1)echo"<FONT COLOR=ORANGE>[未验证]</FONT>";
echo"".variable($rs[2]->value)."<SPAN id=re> <SPAN style=float:left>".$rs[1]->value." IP:".$rs[4]."</SPAN> <SPAN STYLE=float:right> ".date("Y-m-d G:i:s",intval($rs[3]))."&nbsp;"
."[<A href=$FileName?mode=reply&set=yz&id=".$rs[0].">验证</A>]"
."[<A href=$FileName?mode=reply&set=del&id=".$rs[0].">删除</A>]"
."</SPAN></SPAN></DIV>";
$rs->MoveNext();
if($rs->eof) break;}}
$pagecount=Intval($rs->pagecount);
$recordcount=Intval($rs->recordcount);
$rs->Close();
echo "<DIV id=pages>";
for($P=1;$P<=$pagecount;$P++){
if($P!=$page){echo"<A class=page href=$FileName?re=".$_GET["re"]."&p=$P>$P</A>";}else{echo $p;}
if($P>=10){
echo "...";
echo "<A class=page href=$FileName?re=".$_GET["re"]."&p=$pagecount>$pagecount</A>";
break;}}
if($page>1){
echo"&nbsp;&nbsp;[<a href=$FileName?mode=reply&p=".($page-1).">上一页</a>]";}
if($page!=$pagecount){
echo"[<a href=$FileName?mode=reply&p=".($page+1).">下一页</a>]";}
echo"</DIV>";
}
/***********    评论界面     **************/
break;
default:
if(!empty($_GET["re"])&&is_int(intval($_GET["re"]))){
if(!empty($_POST["TiJiao"])&&!empty($_POST["Neirong"])){
$ZuoZhe=$_POST["ZuoZhe"];
$ZuoZhe=str_replace("'","''",$ZuoZhe);
if(empty($ZuoZhe)) $ZuoZhe="网友";
if($YanZhen==1||$YanZhen=="true"){
$yz=0;$i=",验证后展示信息";
}else{
$yz=1;$i="";}
$Rcount=$conn->Execute("select max(bh) from comment");
$Rcount=intval($Rcount[0])+1;
$conn->Execute("Insert into comment values($Rcount,'$ZuoZhe','$NeiRong',".time().",'".IP."',".intval($_GET["re"]).",$yz,0)");
setcookie("Name",$_POST["ZuoZhe"],time()+3600*24*365);
header("Location:".$FileName."?re=".$_GET["re"]."&msg=添加成功$i",2);
die();
}
echo"<DIV id=reDH>";
global $rs;
$rers=$conn->Execute("select neirong from article where bh=".intval($_GET["re"]));
echo Substr($rers[0],0,10) ." 的评论<BR/><BR/>";
$sql="select * from comment where fenlei=".intval($_GET["re"])." and shanchu=0 and yanzhen=1 order by riqi desc";
$rs->open($sql,$conn,1,3);
$rs->pagesize=5;
$page=intval($_GET["p"]);
if(!is_int($page)||$page<1) $page=1;
if($page>$rs->pagecount) $page=$rs->pagecount;
if($rs->eof){print("<BR>没有评论。<BR>");}
else{
$rs->absolutepage=$page;
for($C=0;$C<$rs->pagesize;$C++){
echo "<DIV id=list>".variable($rs[2]->value)."<SPAN id=re> <SPAN style=float:left>".$rs[1]->value." IP:".$rs[4]."</SPAN> <SPAN STYLE=float:right> ".date("Y-m-d G:i:s",intval($rs[3]))."</SPAN></SPAN></DIV>";
$rs->MoveNext();
if($rs->eof) break;}}
$pagecount=Intval($rs->pagecount);
$recordcount=Intval($rs->recordcount);
$rs->Close();
echo "<DIV id=pages>";
for($P=1;$P<=$pagecount;$P++){
if($P!=$page){echo"<A class=page href=$FileName?re=".$_GET["re"]."&p=$P>$P</A>";}else{echo $p;}
if($P>=10){
echo "...";
echo "<A class=page href=$FileName?re=".$_GET["re"]."&p=$pagecount>$pagecount</A>";
break;}}
if($page>1){
echo"&nbsp;&nbsp;[<a href=$FileName?re=".$_GET["re"]."&p=".($page-1).">上一页</a>]";}
if($page!=$pagecount){
echo"[<a href=$FileName?re=".$_GET["re"]."&p=".($page+1).">下一页</a>]";}
echo"</DIV>";
?>
</DIV>
<FORM action="<?=$FileName?>?re=<?=$_GET["re"]?>" method=post>
<DIV id=redit>
昵称:<Input size=18 name="ZuoZhe" value="<?=$_COOKIE["Name"]?>"><BR/>
<TEXTAREA name="Neirong"></TEXTAREA><BR/>
<INPUT type=submit name=TiJiao value="评论">
</DIV>
</FORM>
<?
}else{
/***********    首页界面     **************/
?>
<DIV id="win">
<?PHP
global $rs,$conn;
if(is_int(intval($_GET["del"]))&&!empty($_GET["del"])){
Try{
$conn->Execute("delete from article where bh=".intval($_GET["del"]));
$conn->Execute("delete from comment where fenlei=".intval($_GET["del"]));
header("Location:".$_SERVER["HTTP_REFERER"]."",2);
DIE();
}
Catch(Exception $e)
{
$conn->Execute("update article set ShanChu=1 where bh=".intval($_GET["del"]));
$conn->Execute("update comment set ShanChu=1 where fenlei=".intval($_GET["del"]));
header("Location:".$_SERVER["HTTP_REFERER"]."",2);
DIE();
}}
$sql="select * from article where shanchu=0 order by riqi desc";
$rs->Open($sql,$conn,1,3);
$rs->pagesize=$PageSize;
$page=intval($_GET["p"]);
if(!is_int($page)||$page<1) $page=1;
if($page>$rs->pagecount) $page=$rs->pagecount;
if($rs->eof){print("<BR>当前没有任何新的文章。<BR>");}
else{
$rs->absolutepage=$page;
for($C=0;$C<$rs->pagesize;$C++){
$Recount=$conn->Execute("select count(*) from comment where shanchu=0 and fenlei=".$rs[0]);
$Recount=intval($Recount[0]);
echo"<DIV id=list class=memo>"
."".variable($rs[1]->value)." <DIV id=set>"
."<SPAN class=left>"
."".date("Y-m-d G:i:s",intval($rs[2]))."</SPAN>"
."<SPAN class=right><SPAN id=re>(<A href=$FileName?re=".$rs[0].">评论:$Recount</A>)</SPAN>";
if($QuanXian=="Admin"){
echo"[<A href=$FileName?mode=edit&id=".$rs[0].">修改</A>] "
."[<A href=$FileName?del=".$rs[0].">删除</A>]";
}
echo"</SPAN>"
."</DIV>"
."</DIV>"
."<P>";
$rs->MoveNext();
if($rs->eof) break;}}
$pagecount=Intval($rs->pagecount);
$recordcount=Intval($rs->recordcount);
$rs->Close();
echo "<DIV id=pages>";
for($P=1;$P<=$pagecount;$P++){
if($P!=$page){echo"<A class=page href=$FileName?p=$P>$P</A>";}else{echo $p;}
if($P>=10){
echo "...";
echo "<A class=page href=$FileName?p=$pagecount>$pagecount</A>";
break;}}
if($page>1){
echo"&nbsp;&nbsp;[<a href=$FileName?p=".($page-1).">上一页</a>]";}
if($page!=$pagecount){
echo"[<a href=$FileName?p=".($page+1).">下一页</a>]";}
}
echo"</DIV>";
}
ECHO<<<HTML
</DIV>
<DIV id=footer>
&copy;Js10.com
HTML;
$JieShu=microtime();
echo(" ".($JieShu-$KaiShi)*1000)."ms";
<<<HTML
</DIV>
<SCRIPT>
TRcount=document.getElementsByName("list").length;
for(i=0;i<TRcount;i++){
document.getElementsByName("list").onmouseover=function(){
this.style.background="#F5F9FB";}
document.getElementsByName("list").onmouseout=function(){
this.style.background="#FBFCFE";}}
</SCRIPT>
</BODY>
HTML;
$conn->Close();
?>[/php]
发表于 2011-3-18 14:43:02 | 显示全部楼层
:loveliness: :loveliness: :loveliness:  www.zhutiai.com
发表于 2011-4-10 18:09:22 | 显示全部楼层
牛逼,支持
发表于 2012-5-2 19:33:51 | 显示全部楼层
好东西 多谢楼主
您需要登录后才可以回帖 登录 | 加入无忧

本版积分规则

小黑屋|手机版|Archiver|无忧脚本 ( 苏ICP备05080427号 )|值班电话:027-62300445   鄂公网安备 42011102000433号

GMT+8, 2017-11-18 06:49 , Processed in 0.094873 second(s), 9 queries , Gzip On, Memcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表