文章詳情頁
PHP+MYSQL的文章管理系統(tǒng)(一)
瀏覽:2日期:2024-01-07 16:04:14
###############################################;;此篇文章屬原創(chuàng),如有引用,請(qǐng)標(biāo)明作者信息。;;Email: leo_cdp@yeah.net http://www.cfeng.net/ 本文代碼任意轉(zhuǎn)載,使用請(qǐng)保留此聲明 ###############################################;;去年寫了個(gè)文本管理總覺得有些不爽再加上申請(qǐng)了主機(jī)所以寫個(gè)PHP+MYSQL的對(duì)文章進(jìn)行管理測試期間 受到廣大網(wǎng)友的支持現(xiàn)將代碼公布 功能說明: 文章的基本操作:添加,修改,鎖定,解鎖,推薦,刪除等待 并有強(qiáng)大功能的搜索,評(píng)論,推薦給朋友等功能,并對(duì)安全性進(jìn)行著重加強(qiáng),漂亮的界面人性化的設(shè)計(jì)。 主要文件列表: setup.php;;;;安裝程序,運(yùn)行后即可使用本系統(tǒng)! index.php;;;;顯示 manager.php;;添加,管理文章。 change.php;;;對(duì)已存在文章的操作。 edit_article.php 文章修改 commend.php;;推薦文章給朋友。 read_article.php 文章閱讀。 ping.php;;;;;發(fā)表文章評(píng)論。 search.php;;;文章搜索 type_manager.php;;類型管理 login.php;;;;管理員登陸。 config.php;;;主要配置文件 func.php;;;;;函數(shù)文件 footer.inc,header.inc,nav.inc包含文件。 list.txt;;;;;類型列表 以及其它一些周邊程序 管理系統(tǒng)演示地址: http://www.cfeng.net/article/ ########################config.php 主要配置文件########################## <? $host="localhost";;;;#數(shù)據(jù)庫主機(jī) $database_usn="cfeng.net";;;;##數(shù)據(jù)庫用戶 $database_pwd="cfeng.net";;;;##數(shù)據(jù)庫密碼 $database="cfeng.net"##數(shù)據(jù)庫 $table="cfeng.net";;;##要存放文章的表 $ping_tab="ping_tab1"##存放評(píng)論的表 $admin_usn="leo";;;;;##管理員用戶名 $admin_pwd="leo";;;;;##管理員密碼 $admin_mail="leo_cdp@yeah.net"##管理員信箱 $pagenum="20"##每頁顯示文章數(shù) $sess=md5($admin_usn.$admin_pwd);;;;;##登陸認(rèn)證采用MD5生成 ?> #####################func.php;;函數(shù)文件 ################################### <? require "./inc/config.php"function mscon()##數(shù)據(jù)庫鏈接 {;;;;;global $host,$database_usn,$database_pwd; ;;@mysql_connect("$host","$database_usn","$database_pwd") or die("對(duì)不起,數(shù)據(jù)庫連接錯(cuò)誤!請(qǐng)稍候再來,或與管理員聯(lián)系"); } function check_login() {;;global $sess; if(!session_is_registered("sess_0230a09a07cab1df8112d00b1f9a9719")) ;;;{ ;;;;if($sess_0230a09a07cab1df8112d00b1f9a9719!=$sess) ;;;;;;;{ ;redir("login.php"); ;exit; ;;;;;;;} ;;;} } function redir($addr) ;;{ ;;;;header("location:$addr"); ;;;} function add_article()##本系統(tǒng)實(shí)行寬進(jìn)嚴(yán)出所以添加文章部份顯得略為簡單! { ;;;global $database,$table,$title,$cont,$type,$html; ;;;$dat=date(Y年m月d日); ;;;$title=htmlspecialchars($title); ;;;$query="insert into $table(title,cont,type,time,html) values('$title','$cont','$type','$dat','$html')";;$res=mysql_db_query("$database",$query); ;;;if(!$res) ;;;echo mysql_error(); } function add_hits($id)##添加瀏覽次數(shù)! { global $database,$table; $query="update $table set hits=hits+1 where id=$id";;$res=mysql_db_query("$database",$query); } function add_comm($id)##把本文加為推薦文章 { global $database,$table; $query="update $table set comm=1 where id=$id";;$res=mysql_db_query("$database",$query); } function un_comm($id)##清除推薦! { global $database,$table; $query="update $table set comm='0' where id=$id";;$res=mysql_db_query("$database",$query); } function add_lock($id)##鎖定文章 { global $database,$table; $query="update $table set locked='1' where id=$id";;$res=mysql_db_query("$database",$query); } function un_lock($id)##清除鎖定! { global $database,$table; $query="update $table set locked=0 where id=$id";;$res=mysql_db_query("$database",$query); } function add_p_num($id)##添加評(píng)論次數(shù)! { global $database,$table; $query="update $table set p_num=p_num+1 where id=$id";;$res=mysql_db_query("$database",$query); } function add_del($id)##刪除文章! { global $database,$table; $query="delete from $table where id='$id'";;$res=mysql_db_query("$database",$query); } ########################setup.php 安裝文件###################### <?;;session_start(); require"./inc/func.php" check_login(); ?> <? if($sub) { ;;;$file_cont="<?n #don't edit thisfile use the setup.phpn";;$file_cont.="$host="$host";#your database server addressn";;$file_cont.="$database_usn="$database_usn";n";;$file_cont.="$database_pwd="$database_pwd";n";;$file_cont.="$database="$database";n";;$file_cont.="$table="$table";n";;$file_cont.="$ping_tab="$ping_tab";n";;$file_cont.="$admin_usn="$admin_usn";n";;$file_cont.="$admin_pwd="$admin_pwd";n";;$file_cont.="$admin_mail="$admin_mail";n";;$file_cont.="$pagenum="$pagenum";n";;$file_cont.="$sess=md5($admin_usn.$admin_pwd);n";;$file_cont.="n";;$file_cont.="?>";;$fp=fopen("./inc/config.php","w"); ;;;if(fputs($fp,$file_cont)) ;;;;;;echo "配置完成正檢測各選項(xiàng)的正確性<BR>";;else echo "文件寫入錯(cuò)誤,請(qǐng)檢測文件所在目錄的權(quán)限<br>";;fclose($fp); ;;;;;;echo "正在檢測數(shù)據(jù)連接.........." ; ;;;if(@mysql_connect("$host","$database_usn","$database_pwd")) ;;;;;;{ echo;;"成功!<BR>" ; $query="CREATE TABLE $table( ;;;;;id int(4) NOT NULL auto_increment, ;;;;;title varchar(55) NOT NULL, ;;;;;cont text NOT NULL, ;;;;;time varchar(14) NOT NULL, ;;;;;type varchar(20) NOT NULL, ;;;;;comm int(1) DEFAULT '0' NOT NULL, ;;;;;p_num int(2) DEFAULT '0' NOT NULL, ;;;;;locked int(1) DEFAULT '0' NOT NULL, ;;;;;hits int(4) DEFAULT '0' NOT NULL, ;;;;;html int(1) DEFAULT '1' NOT NULL, ;;;;;PRIMARY KEY (id), ;;;;;UNIQUE id (id), ;;;;;KEY id_2 (id) ;;;;;) " ; if(mysql_db_query($database,$query)) ;;echo"數(shù)據(jù)庫 $table 建立成功<BR>".mysql_error(); else ;;echo"數(shù)據(jù)庫 $table 建立失敗<BR>"$query="CREATE TABLE $ping_tab ( ;;;;;;id int(4) NOT NULL auto_increment, ;;;;;;p_id int(4) DEFAULT '0' NOT NULL, ;;;;;;name varchar(50) NOT NULL, ;;;;;;mail varchar(200) NOT NULL, ;;;;;;p_cont text NOT NULL, ;;;;;;time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, ;;;;;;ip varchar(15) NOT NULL, ;;;;;;PRIMARY KEY (id), ;;;;;;UNIQUE id (id), ;;;;;;KEY id_2 (id) ;;;;;;)"if(mysql_db_query($database,$query)) ;;{ ;;;;echo"用戶評(píng)論數(shù)據(jù)庫 $ping_tab 建立成功<BR>恭喜,文章管理系統(tǒng)安裝成功!請(qǐng)<a href=login.php>這邊走</a>進(jìn)行基本設(shè)置!<BR>";;;$fp=fopen("setup.php","r"); ;;;;$file_cont=fread($fp,filesize("setup.php")); ;;;;$file_cont="<? nsession_start();nrequire"./inc/func.php";n check_login();n?>n".$file_cont; ;;;;$fp=fopen("setup.php","w"); ;;;;fputs($fp,$file_cont); ;;;;fclose($fp); ;;} else ;;echo"用戶評(píng)論數(shù)據(jù)庫$ping_tab建立失敗<BR>";;;} ;;;else ;;;;;;echo "數(shù)據(jù)庫連接失敗!請(qǐng)檢測你用戶名密碼的正確性!<BR>";exit(); ;;} require "./inc/header.inc"?> <script language="javascript"> function db_pwd() { ;;var theResult = true; ;;var elem4 = null; ;;if (document.forms[0].elements[2].value == "" || document.forms[0].elements[2].value!=document.forms[0].elements[3].value) ;;{ ;;;;alert("您兩次輸入的數(shù)據(jù)庫密碼不一致,或者為空!"); ;;;;document.forms[0].elements[2].value="";;;document.forms[0].elements[3].value="";;;theResult = false; ;;;;;} ;;return theResult; } function admin_pwd() { ;;var theResult = true; ;;var elem4 = null; if (document.forms[0].elements[8].value == "" || document.forms[0].elements[8].value!=document.forms[0].elements[9].value) ;;{ ;;;;alert("您兩次輸入的管理員密碼不一致,或者為空!"); ;;;;document.forms[0].elements[8].value="";;;document.forms[0].elements[9].value="";;;theResult = false; ;;;;;} ;;return theResult; } function go() { var theResult=true; theResult =db_pwd()&&admin_pwd(); return theResult; } </script> </head> <body bgcolor="#FFFFFF"> <? require "./inc/nav.inc";?> <form name="form1" method="post" action="<? echo $PHP_SELF; ?>" onsubmit="return go()";> ;;<table border="0" cellspacing="0" cellpadding="0" align="center" style=text-align:left;> ;;;;<tr> ;;;;;;<td colspan="3"> <div align="center">藍(lán)狐文章管理安裝程序<br> ;;(請(qǐng)正確填寫以下內(nèi)容否則程序?qū)o法使用)</div> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>數(shù)據(jù)庫服務(wù)器:</td> ;;;;;;<td colspan="2"> <input type="text" name="host" value="localhost" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>數(shù)據(jù)庫用戶名: </td> ;;;;;;<td colspan="2"> <input type="text" name="database_usn" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>數(shù)據(jù)庫用戶密碼:</td> ;;;;;;<td colspan="2"> <input type="password" name="database_pwd" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>數(shù)據(jù)庫密碼確認(rèn):</td> ;;;;;;<td colspan="2"> <input type="password" name="database_pwd2" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>數(shù)據(jù)庫名:</td> ;;;;;;<td colspan="2"> <input type="text" name="database" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>存放文章的表:</td> ;;;;;;<td colspan="2"> <input type="text" name="table" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>存放評(píng)論的表:</td> ;;;;;;<td colspan="2"> <input type="text" name="ping_tab" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>管理員用戶名:</td> ;;;;;;<td colspan="2"> <input type="text" name="admin_usn" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>管理員密碼:</td> ;;;;;;<td colspan="2"> <input type="password" name="admin_pwd" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>管理員密碼確認(rèn):</td> ;;;;;;<td colspan="2"> <input type="password" name="admin_pwd2" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>管理員郵件地址:</td> ;;;;;;<td colspan="2"> <input type="text" name="admin_mail" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td>每頁顯示文章數(shù):</td> ;;;;;;<td colspan="2"> <input type="text" name="pagenum" class="border" size="30"> ;;;;;;</td> ;;;;</tr> ;;;;<tr> ;;;;;;<td> <div align="center"><br> </div> ;;;;;;</td> ;;;;;;<td> <div align="left"><br> ;;<input type="submit" name="sub" value="submit" class="border"> ;; ;;<input type="reset" name="reset" value="reset" class="border"> </div> ;;;;;;</td> ;;;;</tr> ;;</table> ;;<p> </p> ;;</form> <?require "./inc/footer.inc";?>;
標(biāo)簽:
PHP
排行榜
