PHP+ACCESS 文章管理程序代码


Posted in PHP onJune 21, 2010
<?php 
session_start(); 
//========================== 
//作者:biyuan 
//时间:2006.07 
//联系:QQ6010707 
//========================== 
?> 
<html> 
<head> 
<title>碧原网络PHP+ACCESS文章管理系统</title> 
<meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
<style type="text/css"> 
body { 
margin:0px; 
text-align:center; 
font-size:12px; 
font-family:verdana; 
} 
td { 
font-size:12px; 
height:28px; 
padding:4px; 
font-family:verdana; 
} 
A:link, 
A:visited, 
A:active { 
color: #005a17; text-decoration: none; 
} 
A:hover { 
color: #ff5a00; text-decoration: underline; 
} 
</style> 
</head> 
<body> 
<?php 
//================================== 
//连接数据库 
//================================== 
@$conn = new com("ADODB.Connection"); 
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("article.mdb")); 
//================================== 
//文章导航 
//================================== 
function article_menu(){ 
global $conn; 
@$sql = "Select * From List"; 
@$rs = $conn->Execute($sql); 
while(!$rs->Eof){ 
echo "| <a href=\"?classid=" . $rs->Fields[2]->value . "\">" . $rs->Fields[1]->value . "</a> "; 
$rs->MoveNext(); 
} 
echo "| <a href=\"?admin=login\">后台管理</a>\r\n"; 
$rs->Close(); 
if(@$_SESSION["ARTICLEADMIN"] == "BY_PHP_ARTICLE"){ 
echo "<br />管理选项-> | <a href=\"?admin=class\">分类管理</a> | <a href=\"?admin=insert\">发表文章</a> | <a href=\"?admin=list\">文章列表</a> | <a href=\"?admin=logout\">退出登陆</a>"; 
} 
} 
//================================== 
//文章列表:article_list(文章分类ID) 
//================================== 
function article_list($str){ 
global $conn; 
@$sql = "Select id,by_title,by_name,by_time,by_count From Article Where by_class = " . $str . " Order By id desc"; 
@$rs = $conn->Execute($sql); 
if(!$rs->Eof){ 
echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n" 
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n" 
. " <td>文章标题</td><td>文章作者</td><td>发表时间</td><td>浏览次数</td>\r\n" 
. " </tr>\r\n"; 
while(!$rs->Eof){ 
echo " <tr bgcolor=\"#FFFFFF\">\r\n" 
. " <td><a href=\"?artid=" . $rs->Fields[0]->value . "\">" . $rs->Fields[1]->value . "</a></td><td>" . $rs->Fields[2]->value . "</td><td>" . date("Y-m-d H:i:s",$rs->Fields[3]->value) . "</td><td>" . $rs->Fields[4]->value . "</td>\r\n" 
. " </tr>\r\n"; 
$rs->MoveNext(); 
} 
echo "</table>\r\n"; 
} 
else { 
echo "<br />该分类不存在或暂时没有任何文章!"; 
} 
$rs->Close(); 
} 
//================================== 
//文章详细:article_look(文章ID) 
//================================== 
function article_look($str){ 
global $conn; 
@$sql = "Select * From Article Where id = " . $str; 
@$rs = $conn->Execute($sql); 
@$usql= "Update Article Set by_count = (by_count + 1) Where id = " . $str; 
$conn->Execute($usql); 
if(!$rs->Eof){ 
@$body = $rs->Fields[5]->value; 
$body = str_replace("[url=file://%22,%22%22,$body/]\\","",$body[/url]); 
echo "<table border=\"0\" width=\"60%\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n" 
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n" 
. " <td style=\"font-size:14px;font-weight:bold\">" . $rs->Fields[1]->value . "</td>\r\n" 
. " </tr>\r\n" 
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n" 
. " <td>文章作者:" . $rs->Fields[2]->value . " | 发表时间:" . date("Y-m-d H:i:s",$rs->Fields[3]->value) . " | 浏览次数:" . $rs->Fields[4]->value . "</td>\r\n" 
. " </tr>\r\n" 
. " <tr bgcolor=\"#FFFFFF\">\r\n" 
. " <td>" . $body . "</td>\r\n" 
. " </tr>\r\n" 
. " <tr bgcolor=\"#F3F3F3\">\r\n" 
. " <td align=\"right\">【 <a href=\"javascript:history.back();\">返 回</a> 】  【 <a href=\"javascript:print();\">打 印</a> 】  【 <a href=\"javascript:close();\">关 闭</a> 】</td>\r\n" 
. " </tr>\r\n" 
. " </table>\r\n" 
. " <script language=\"JavaScript\">document.title += \"--" . $rs->Fields[1]->value . "\";</script>\r\n"; 
} 
else { 
echo "<br />该文章不存在或已被管理员删除!"; 
} 
$rs->Close(); 
} 
//================================== 
//后台:分类管理 
//================================== 
function admin_class(){ 
global $conn; 
@$sql = "Select * From List"; 
@$rs = $conn->Execute($sql); 
echo "<form action=\"\" method=\"post\" name=\"frm\">\r\n"; 
while(!$rs->Eof){ 
echo "类别:<input type=\"text\" value=\"" . $rs->Fields[1]->value . "\" name=\"class_" . $rs->Fields[0]->value . "\" /> 编号:<input type=\"text\" value=\"" . $rs->Fields[2]->value . "\" name=\"class_cid_" . $rs->Fields[0]->value . "\" /> <input type=\"button\" value=\"修改\" onclick=\"frm.action='?admin=class&class=edit&id=" . $rs->Fields[0]->value . "';submit();\" /> <input type=\"button\" value=\"删除\" onclick=\"frm.action='?admin=class&class=del&id=" . $rs->Fields[0]->value . "';submit();\" /><br />\r\n"; 
$rs->MoveNext(); 
} 
echo "类别:<input type=\"text\" name=\"class_name\" /> 编号:<input type=\"text\" name=\"class_cid\" /> <input type=\"button\" value=\"增加\" onclick=\"frm.action='?admin=class&class=add';submit();\" /> <input type=\"button\" value=\"闲置\" disabled />\r\n" 
. "</form>\r\n"; 
//增加一个类别 
if(@$_GET["class"] == "add"){ 
if(@$_POST["class_name"] == "" || @$_POST["class_cid"] == ""){ 
echo "<br />填写不完整!"; 
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>"; 
exit(); 
} 
else { 
@$sql = "Insert into List(by_list,by_cid) Values('" . $_POST["class_name"] . "' , '" . $_POST["class_cid"] . "')"; 
$conn->Execute($sql); 
echo "<br />添加成功!"; 
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=class';\", 2000);</script>"; 
} 
} 
//修改一个类别 
if(@$_GET["class"] == "edit"){ 
if(@$_POST["class_" . $_GET["id"]] == "" || @$_POST["class_cid_" . $_GET["id"]] == ""){ 
echo "<br />填写不完整!"; 
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>"; 
exit(); 
} 
else { 
@$sql = "Update List Set by_list = '" . $_POST["class_" . $_GET["id"]] . "' , by_cid = '" . $_POST["class_cid_" . $_GET["id"]] . "' Where id = " . $_GET["id"]; 
$conn->Execute($sql); 
echo "<br />修改成功!"; 
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=class';\", 2000);</script>"; 
} 
} 
//删除一个类别 
if(@$_GET["class"] == "del"){ 
@$sql = "Delete From List Where id = " . $_GET["id"]; 
$conn->Execute($sql); 
echo "<br />删除成功!"; 
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=class';\", 100);</script>"; 
} 
} 
//================================== 
//后台:发表文章(支持HTML) 
//================================== 
function admin_insert(){ 
global $conn; 
if(@$_GET["innert"] == "add"){ 
if(@$_POST["title"] == "" || @$_POST["name"] == "" || @$_POST["class"] == "" || @$_POST["body"] == ""){ 
echo "<br />填写不完整!"; 
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>"; 
exit(); 
} 
else { 
@$body = $_POST["body"]; 
$body = str_replace("'", "''", $body); 
$body = str_replace("\r\n", "<br />", $body); 
@$sql = "Insert into article(by_title,by_name,by_time,by_count,by_body,by_class) Values('" . $_POST["title"] . "' , '" . $_POST["name"] . "' , #" . date("Y-m-d G:i:s") . "# , 0 , '" . $body . "' , '" . $_POST["class"] . "')"; 
$conn->Execute($sql); 
echo "<br />添加成功!"; 
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=insert';\", 2000);</script>"; 
} 
} 
else { 
echo "<div style=\"width:590px;text-align:left\">\r\n" 
. "<form action=\"?admin=insert&innert=add\" method=\"post\">\r\n" 
. "文章标题:<input type=\"text\" name=\"title\" /><br />\r\n" 
. "文章作者:<input type=\"text\" name=\"name\" /><br />\r\n" 
. "文章类别:<select name=\"class\">\r\n"; 
@$sql = "Select * From List"; 
@$rs = $conn->Execute($sql); 
while(!$rs->Eof){ 
echo "<option value=\"" . $rs->Fields[2]->value . "\">" . $rs->Fields[1]->value . "</option>\r\n"; 
$rs->MoveNext(); 
} 
echo "</select><br />\r\n" 
. "文章正文:<textarea cols=\"70\" rows=\"14\" name=\"body\"></textarea><br />\r\n" 
. "<center><input type=\"submit\" value=\"提交\" /> <input type=\"reset\" value=\"重置\" /></center>\r\n" 
. "</form>\r\n" 
. "</div>\r\n"; 
} 
} 
//================================== 
//后台:文章列表 
//================================== 
function admin_list(){ 
global $conn; 
@$sql = "Select id,by_title,by_name,by_time,by_count,by_class From Article Order By id desc"; 
@$rs = $conn->Execute($sql); 
if(!$rs->Eof){ 
echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n" 
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n" 
. " <td>文章标题</td><td>文章分类<td>文章作者</td><td>发表时间</td><td>浏览次数</td><td>操作</td>\r\n" 
. " </tr>\r\n"; 
while(!$rs->Eof){ 
@$sql = "Select * From List Where by_cid = " . $rs->Fields[5]->value; 
@$crs = $conn->Execute($sql); 
@$cid = $crs->Fields[1]->value; 
echo " <tr bgcolor=\"#FFFFFF\">\r\n" 
. " <td><a href=\"?artid=" . $rs->Fields[0]->value . "\">" . $rs->Fields[1]->value . "</a></td><td>" . $cid . "</td><td>" . $rs->Fields[2]->value . "</td><td>" . $rs->Fields[3]->value . "</td><td>" . $rs->Fields[4]->value . "</td><td><a href=\"?admin=list&list=edit&id=" . $rs->Fields[0]->value . "\">编辑</a> | <a href=\"?admin=list&list=del&id=" . $rs->Fields[0]->value . "\">删除</a></td>\r\n" 
. " </tr>\r\n"; 
$crs->Close(); 
$rs->MoveNext(); 
} 
echo "</table>\r\n"; 
} 
else { 
echo "<br />该分类不存在或暂时没有任何文章!"; 
} 
$rs->Close(); 
//修改文章 
if(@$_GET["list"] == "edit"){ 
if(@$_GET["edit"] == "true"){ 
if(@$_POST["title"] == "" || @$_POST["name"] == "" || @$_POST["class"] == "" || @$_POST["body"] == ""){ 
echo "<br />填写不完整!"; 
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>"; 
exit(); 
} 
else { 
@$body = $_POST["body"]; 
$body = str_replace("'", "''", $body); 
$body = str_replace("\r\n", "<br />", $body); 
@$sql = "Update article Set by_title = '" . $_POST["title"] . "' , by_name = '" . $_POST["name"] . "' , by_count = " . $_POST["count"] . " , by_body = '" . $body . "' , by_class = '" . $_POST["class"] . "' Where id = " . $_GET["id"]; 
$conn->Execute($sql); 
echo "<br />修改成功!"; 
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=list';\", 2000);</script>"; 
} 
} 
else { 
@$sql = "Select * From Article Where id = " . $_GET["id"]; 
@$rs = $conn->Execute($sql); 
echo "<div style=\"width:590px;text-align:left\">\r\n" 
. "<form action=\"?admin=list&list=edit&edit=true&id=" . $rs->fields[0]->value . "\" method=\"post\">\r\n" 
. "文章标题:<input type=\"text\" name=\"title\" value=\"" . $rs->fields[1]->value . "\" /><br />\r\n" 
. "文章作者:<input type=\"text\" name=\"name\" value=\"" . $rs->fields[2]->value . "\" /><br />\r\n" 
. "浏览次数:<input type=\"text\" name=\"count\" value=\"" . $rs->fields[4]->value . "\" /><br />\r\n" 
. "文章类别:<select name=\"class\" id=\"class\">\r\n"; 
@$sql = "Select * From List"; 
@$crs = $conn->Execute($sql); 
while(!$crs->Eof){ 
echo "<option value=\"" . $crs->Fields[2]->value . "\">" . $crs->Fields[1]->value . "</option>\r\n"; 
$crs->MoveNext(); 
} 
$crs->close(); 
@$body = $rs->Fields[5]->value; 
$body = str_replace("<br />","\r\n",$body); 
echo "</select><br />\r\n" 
. "<script language=\"JavaScript\">\r\n" 
. "document.getElementById(\"class\").selectedIndex = " . $rs->fields[6]->value . " - 1;\r\n" 
. "</script>\r\n" 
. "文章正文:<textarea cols=\"70\" rows=\"14\" name=\"body\">" . $body . "</textarea><br />\r\n" 
. "<center><input type=\"submit\" value=\"提交\" /> <input type=\"reset\" value=\"重置\" /></center>\r\n" 
. "</form>\r\n" 
. "</div>\r\n"; 
} 
} 
//删除文章 
if(@$_GET["list"] == "del"){ 
@$sql = "Delete From Article Where id = " . $_GET["id"]; 
$conn->Execute($sql); 
echo "<br />删除成功!"; 
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=list';\", 100);</script>"; 
} 
} 
//================================== 
//权限验证 
//================================== 
function admin_session(){ 
if(@$_SESSION["ARTICLEADMIN"] != "BY_PHP_ARTICLE"){ 
echo "<br />请先登陆!"; 
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=login';\", 2000);</script>"; 
exit(); 
} 
} 
//================================== 
//后台登陆 
//================================== 
function admin_login(){ 
if(@$_SESSION["ARTICLEADMIN"] == "BY_PHP_ARTICLE"){ 
echo "<script language=\"JavaScript\">window.location.href='?admin=admin';</script>"; 
} 
else{ 
echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n" 
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n" 
. " <td><strong>管理员登陆</strong></td>\r\n" 
. " </tr>\r\n" 
. " <tr bgcolor=\"#FFFFFF\">\r\n" 
. " <form method=\"post\" action=\"?admin=check\">\r\n" 
. " <td><input type=\"password\" name=\"adminPass\" /><input type=\"submit\" value=\"确定\" /></td>\r\n" 
. " </form>\r\n" 
. " </tr>\r\n" 
. "</table>\r\n"; 
} 
} 
//================================== 
//登陆验证 
//================================== 
function admin_check(){ 
if(trim($_POST["adminPass"]) != "admin"){ 
echo "<br />错误的密码!"; 
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>"; 
} 
else { 
echo "<br />登陆成功!"; 
@$_SESSION["ARTICLEADMIN"] = "BY_PHP_ARTICLE"; 
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=admin';\", 2000);</script>"; 
} 
} 
//================================== 
//URL参数列表 
//================================== 
function page_load(){ 
@$classid = $_GET["classid"]; 
if($classid != ""){ 
if(!is_numeric($classid)){ 
echo "<br />错误的参数!"; 
return false; 
} 
else { 
article_list($classid); 
} 
} 
@$artid = $_GET["artid"]; 
if($artid != ""){ 
if(!is_numeric($artid)){ 
echo "<br />错误的参数!"; 
return false; 
} 
else { 
article_look($artid); 
} 
} 
@$admin = $_GET["admin"]; 
if($admin == "login"){ 
admin_login(); 
} 
if($admin == "check"){ 
admin_check(); 
} 
if($admin == "admin"){ 
admin_session(); 
echo "<br />登陆成功!请选择功能菜单进行操作."; 
} 
if($admin == "logout"){ 
session_destroy(); 
echo "<br />已成功退出!"; 
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=login';\", 2000);</script>"; 
} 
if($admin == "class"){ 
admin_session(); 
admin_class(); 
} 
if($admin == "insert"){ 
admin_session(); 
admin_insert(); 
} 
if($admin == "list"){ 
admin_session(); 
admin_list(); 
} 
if($classid == "" && $artid == "" && $admin == ""){ 
echo "<script language=\"JavaScript\">window.location.href='?classid=1';</script>"; 
} 
} 
?> 
<div style="width:100%;text-align:left;background:#cccccc;line-height:20px;"> 
<br /><br /><br />文章分类-> <?=article_menu();?> 
</div> 
<?=page_load();?> 
<?php 
$conn->Close(); 
?> 
</body> 
</html>
PHP 相关文章推荐
PHP+MySQL5.0中文乱码解决方法
Nov 20 PHP
追求程序速度,而不是编程的速度
Apr 23 PHP
PHP的单引号和双引号 字符串效率
May 27 PHP
php基础设计模式大全(注册树模式、工厂模式、单列模式)
Aug 31 PHP
php获取当前页面完整URL地址
Dec 30 PHP
ThinkPHP模板Volist标签嵌套循环输出多维数组的方法
Mar 23 PHP
ThinkPHP使用Ueditor的方法详解
May 20 PHP
php实现URL加密解密的方法
Nov 17 PHP
PHP编程实现csv文件导入mysql数据库的方法
Apr 29 PHP
PHP实现的支付宝支付功能示例
Mar 26 PHP
laravel admin实现分类树/模型树的示例代码
Jun 10 PHP
PHP实现递归的三种方法
Jul 04 PHP
php $_SERVER[&quot;REQUEST_URI&quot;]获取值的通用解决方法
Jun 21 #PHP
php自动加载的两种实现方法
Jun 21 #PHP
PHP定时自动生成静态HTML的实现代码
Jun 20 #PHP
PHP XML操作的各种方法解析(比较详细)
Jun 17 #PHP
PHP操作xml代码
Jun 17 #PHP
PHP XML error parsing SOAP payload on line 1
Jun 17 #PHP
PHP zlib扩展实现页面GZIP压缩输出
Jun 17 #PHP
You might like
使用 PHPStorm 开发 Laravel
2015/03/24 PHP
PHP 下载文件时如何自动添加bom头及解释BOM头和去掉bom头的方法
2016/01/04 PHP
Symfony2开发之控制器用法实例分析
2016/02/05 PHP
PHP如何使用cURL实现Get和Post请求
2020/07/11 PHP
基于JQuery制作的产品广告效果
2010/12/08 Javascript
jQuery 全选/反选以及单击行改变背景色实例
2013/07/02 Javascript
JS对象转换为Jquery对象实现代码
2013/12/29 Javascript
jQuery+AJAX实现遮罩层登录验证界面(附源码)
2020/09/13 Javascript
基于jQuery实现的无刷新表格分页实例
2016/02/17 Javascript
JavaScript利用正则表达式替换字符串中的内容
2016/12/12 Javascript
微信小程序开发之圆形菜单 仿建行圆形菜单实例
2016/12/12 Javascript
js实现自定义路由
2017/02/04 Javascript
Nodejs实现短信验证码功能
2017/02/09 NodeJs
微信小程序scroll-view实现横向滚动和上拉加载示例
2017/03/06 Javascript
JS使用setInterval实现的简单计时器功能示例
2018/04/19 Javascript
Node对CommonJS的模块规范
2019/11/06 Javascript
python实现通过代理服务器访问远程url的方法
2015/04/29 Python
Python中利用Scipy包的SIFT方法进行图片识别的实例教程
2016/06/03 Python
python挖矿算力测试程序详解
2019/07/03 Python
Python生命游戏实现原理及过程解析(附源代码)
2019/08/01 Python
关于python字符串方法分类详解
2019/08/20 Python
Python 实现Serial 与STM32J进行串口通讯
2019/12/18 Python
django的403/404/500错误自定义页面的配置方式
2020/05/21 Python
python numpy矩阵信息说明,shape,size,dtype
2020/05/22 Python
Python datetime 如何处理时区信息
2020/09/02 Python
Python 列表反转显示的四种方法
2020/11/16 Python
python 实时调取摄像头的示例代码
2020/11/25 Python
HTML5 预加载让页面得以快速呈现
2013/08/13 HTML / CSS
美国购买韩国护肤和美容产品网站:Althea Korea
2020/11/16 全球购物
C++的几个面试题附答案
2016/08/03 面试题
资深地理教师自我评价
2013/09/21 职场文书
教师师德反思材料
2014/02/15 职场文书
护士节演讲稿开场白
2014/08/25 职场文书
大班上学期个人总结
2015/02/13 职场文书
社区青年志愿者活动总结
2015/05/06 职场文书
爱国主义影片观后感
2015/06/18 职场文书