Article management system of PHP + MYSQL (1) ######################################## #######
This article is original. if it is referenced, please indicate the author's information.
Email: leo_cdp@yeah.net
Http://www.cfeng.net/
The code in this article is reproduced at will. please keep this statement for use
######################################## #######
Last year, I wrote a text management document. I always felt a little uncomfortable. when I applied for a host, I wrote a PHP + MYSQL document for management testing.
Supported by a large number of netizens, the code is now published
Function description:
Basic operations of the article: add, modify, lock, unlock, recommend, delete wait
It also provides powerful functions such as search, comment, and recommendation to friends. It also focuses on enhanced security and a user-friendly design of beautiful interfaces.
Main file list:
Setup. php installation program. you can use this system after running it!
Index. php display
Manager. php add and manage articles.
Change. php operations on existing articles.
Edit_article.php article modification
Commend. php recommends articles to friends.
Read read_article.php.
Ping. php post comments.
Search. php article search
Type_manager.php type management
Log on as the login. php administrator.
Config. php main configuration file
Func. php function file
Footer. inc, header. inc, nav. inc contains files.
List.txt type list
And other peripheral programs
Management System Demo address:
Http://www.cfeng.net/article/
######################## Config. main php configuration files ##########################
$ Host = "localhost"; # Database host
$ Database_usn = "cfeng.net"; # Database User
$ Database_pwd = "cfeng.net"; # database password
$ Database = "cfeng.net"; # database
$ Table = "cfeng.net"; # table for storing articles
$ Ping_tab = "ping_tab1"; # Comment table
$ Admin_usn = "leo"; # administrator username
$ Admin_pwd = "leo"; # Administrator password
$ Admin_mail = "leo_cdp@yeah.net"; # administrator mailbox
$ Pagenum = "20"; # Number of articles displayed on each page
$ Sess = md5 ($ admin_usn. $ admin_pwd); # Use MD5 to generate login authentication
?>
##################### Func. php function file ###################################
Require "./inc/config. php ";
Function mscon () # Database link
{
Global $ host, $ database_usn, $ database_pwd;
@ Mysql_connect ("$ host", "$ database_usn", "$ database_pwd") or die ("Sorry, database connection error! Please come back later or contact the administrator ");
}
Function check_login ()
{Global $ sess;
If (! Session_is_registered ("sess_0230a09a07cab1df8da-d00b1f9a9719 "))
{
If ($ sess_0230a09a07cab1df8127d00b1f9a9719! = $ Sess)
{
Redir ("login. php ");
Exit;
}
}
}
Function redir ($ addr)
{
Header ("location: $ addr ");
}
Function add_article () # this system implements wide-forward and strict-out, so it is a little simpler to add the article!
{
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) # add browsing times!
{
Global $ database, $ table;
$ Query = "update $ table set hits = hits + 1 where id = $ id ";
$ Res = mysql_db_query ("$ database", $ query );
}
Function add_comm ($ id) # add this article as a recommendation article
{
Global $ database, $ table;
$ Query = "update $ table set comm = 1 where id = $ id ";
$ Res = mysql_db_query ("$ database", $ query );
}
Function un_comm ($ id) # clear recommendation!
{
Global $ database, $ table;
$ Query = "update $ table set comm = '0' where id = $ id ";
$ Res = mysql_db_query ("$ database", $ query );
}
Function add_lock ($ id) # lock an article
{
Global $ database, $ table;
$ Query = "update $ table set locked = '1' where id = $ id ";
$ Res = mysql_db_query ("$ database", $ query );
}
Function un_lock ($ id) # clear lock!
{
Global $ database, $ table;
$ Query = "update $ table set locked = 0 where id = $ id ";
$ Res = mysql_db_query ("$ database", $ query );
}
Function add_p_num ($ id) # number of comments added!
{
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) # delete an article!
{
Global $ database, $ table;
$ Query = "delete from $ table where id = '$ ID '";
$ Res = mysql_db_query ("$ database", $ query );
}
######################## Setup. php installation file ######################
Session_start ();
Require "./inc/func. php ";
Check_login ();
?>
If ($ sub)
{
$ File_cont =" $ File_cont. = "\ $ host = \" $ host \ "; # your database server address \ n ";
$ 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 "the configuration is complete and the correctness of each option is checked.
";
Else echo "file write error. check the permission of the directory where the file is located.
";
Fclose ($ fp );
Echo "detecting data connection ..........";
If (@ mysql_connect ("$ host", "$ database_usn", "$ database_pwd "))
{
Echo "successful!
";
$ 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 "database $ table created successfully
". Mysql_error ();
Else
Echo "database $ table creation failed
";
$ 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 '2014-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 "user comment database $ ping_tab created successfully
Congratulations! the article management system is successfully installed! Please go here for basic settings!
";
$ Fp = fopen ("setup. php", "r ");
$ File_cont = fread ($ fp, filesize ("setup. php "));
$ File_cont =" \ N ". $ file_cont;
$ Fp = fopen ("setup. php", "w ");
Fputs ($ fp, $ file_cont );
Fclose ($ fp );
}
Else
Echo "user comment database $ ping_tab creation failed
";
}
Else
Echo "database connection failed! Check whether your username and password are correct!
";
Exit ();
}
Require "./inc/header. inc ";
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.