PHP article management, _PHP tutorial
PHP article management,
Function description:
Basic operations of articles: add, modify, lock, unlock, recommend, delete and wait
It also has powerful functions such as searching, commenting, and recommending to friends. It also focuses on enhancing security and has a beautiful interface with a user-friendly design.
Main file list:
setup.php installation program, you can use this system after running it!
index.php display
manager.php adds and manages articles.
change.php operates on existing articles.
edit_article.php Article modification
commend.php recommends articles to friends.
read_article.php article reading.
ping.php Post comments on articles.
search.php article search
type_manager.php type management
login.php Administrator login.
config.php main configuration file
func.php function file
footer.inc, header.inc, nav.inc include files.
list.txt type list
And some other peripheral programs
Management system demonstration address:
http://www.cfeng.net/article/
#######################config.php Main configuration file#################### ######
$host="localhost"; #Database host
$database_usn="cfeng.net"; ##Database User
$database_pwd="cfeng.net"; ##Database password
$database="cfeng.net"; ##Database
$table="cfeng.net"; ##Table to store articles
$ping_tab="ping_tab1"; ##Table to store comments
$admin_usn="leo"; ##Administrator username
$admin_pwd="leo"; ##Administrator password
$admin_mail="leo_cdp@yeah.net"; ##Administrator's mailbox
$pagenum="20"; ##Display the number of articles per page
$sess=md5($admin_usn.$admin_pwd); ##Login authentication is generated using MD5
?>
#####################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_0230a09a07cab1df8112d00b1f9a9719"))
{
if($sess_0230a09a07cab1df8112d00b1f9a9719!=$sess)
{
redir("login.php");
exit;
}
}
}
function redir($addr)
{
header("location:$addr");
}
function add_article()##This system implements wide entry and strict exit, so adding articles seems a little simple!
{
global $database,$table,$title,$cont,$type,$html;
$dat=date(Y year m month d day);
$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 the number of views!
{
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 recommended 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 article
{
global $database,$table;
$query="update $table set locked='1' where id=$id";
$res=mysql_db_query("$database",$query);
}
function un_lock($id)##Clear the 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 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=" #don't edit thisfile use the setup.php
";
$file_cont.="$host="$host";#your database server address
";
$file_cont.="$database_usn="$database_usn"; ";
$file_cont.="$database_pwd="$database_pwd"; ";
$file_cont.="$database="$database"; ";
$file_cont.="$table="$table"; ";
$file_cont.="$ping_tab="$ping_tab"; ";
$file_cont.="$admin_usn="$admin_usn"; ";
$file_cont.="$admin_pwd="$admin_pwd"; ";
$file_cont.="$admin_mail="$admin_mail"; ";
$file_cont.="$pagenum="$pagenum"; ";
$file_cont.="$sess=md5($admin_usn.$admin_pwd); ";
$file_cont.=" ";
$file_cont.="?>";
$fp=fopen("./inc/config.php","w");
if(fputs($fp,$file_cont))
echo "配置完成正检测各选项的正确性
";
else echo "文件写入错误,请检测文件所在目录的权限
";
fclose($fp);
echo "正在检测数据连接.........." ;
if(@mysql_connect("$host","$database_usn","$database_pwd"))
{
echo "成功!
" ;
$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"数据库 $table 建立成功
".mysql_error();
else
echo"数据库 $table 建立失败
";
$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"用户评论数据库 $ping_tab 建立成功
恭喜,文章管理系统安装成功!请这边走进行基本设置!
";
$fp=fopen("setup.php","r");
$file_cont=fread($fp,filesize("setup.php"));
$file_cont=" session_start(); require"./inc/func.php";
check_login(); ?> ".$file_cont;
$fp=fopen("setup.php","w");
fputs($fp,$file_cont);
fclose($fp);
}
else
echo"用户评论数据库$ping_tab建立失败
";
}
else
echo "数据库连接失败!请检测你用户名密码的正确性!
";
exit();
}
require "./inc/header.inc";
?>
require "./inc/nav.inc";?>

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software