欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP+ACCESS 文章管理程序代码

程序员文章站 2023-11-09 22:40:34
复制代码 代码如下:
复制代码 代码如下:

<?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>