I learned PHP from myself for more than half a year, and it was intermittent, but eventually strengthened my idea and continued PHP. So I wrote this PHP blog to find a stable PHP job, I don't want to raise my salary, but I want to take a place to learn PHP for more than half a year. It's intermittent, but eventually I have strengthened my idea to continue with PHP, so I wrote this PHP blog to find a stable PHP job. I don't want to pay a high salary, but I want to keep it. I can understand most of the English documents. I am not stupid and love to learn. If you are interested, please contact me! Come on with sincerity! Qq: 240382473
I will publish all the key code and documentation three to five times, and apply all the styles in the blog background to the blog garden!
Note:
1. the MVC Architecture is not fully used, but the idea is like this. Because it cannot write a very stable MVC Architecture.
2. jquery ajax is rarely used. It is not very familiar with jquery ajax and cannot be used freely. It is no problem to use AJAX for message books.
3. There are several public classes and other codes are hand-written. If there are any deficiencies, please point out them a lot. Thank you very much.
4. You are welcome to give criticism and guidance, but please give your reasons.
Let's get down to the truth: first look at the database architecture
The engines of these tables are MYISAM, which facilitates access. (The yellow key represents the primary key, the Blue Diamond represents the non-empty field, and the white diamond represents the null field.) The link in the diagram only indicates a potential relationship between them, cannot be associated during operation. because the search engine is MyISAM. Therefore, joint queries and multi-Table operations are required.
I will pick out the most important post and special fields in the category two tables for detailed description. Others are important.
Post:
Post_id
Category_id varchar (10) is used to index the classification of a blog. Here, category_id is also a string type, so you can set multiple categories for each blog.
Type varchar (20) is used to distinguish post, article, and diary. It can also be set to postDraft and articleDraft;
Whether the visiable blog is visible
Other common fields such as title, content, creation time, last modification time, browsing times, comments, tags, comments allowed, and reserved fields.
Category:
Parent, count_child_number, count_parent_number for future extension
You can set the category of the album, blog, and diary respectively.
Other common fields such as name, description, Creation Time, and visibility
Comment:
Address user IP address
User_agent user browser type
Other fields...
Server Architecture
PHP5.4.2 + MYSQL 5.523 + APACHE 2.2.22 + Windows NT ARIST-PC 6.1 build 7600 (Windows 7 Home Basic Edition) i586 (local)
Blog Architecture
Background directory:
Background directory description:
Assert stores various resources such as js, css, and image.
Class stores common classes of our classes, such as database operations, paging classes, and most of our models...
Extention stores some extensions such as the mce rich Editor
Config stores our configuration information
Templates stores all templates (smarty is not used)
Upload stores photos and other files.
The admin root directory contains some similar controllers such as index. php, post. php, article. php, and photo. php.
Let's first look at admin/config. php
The Code is as follows:
Ini_set ("display_errors", true );
Date_default_timezone_set ("Asia/Shanghai ");
// Root and direcotry separate
Define ('ds', DIRECTORY_SEPARATOR );
Define ('root', dirname (_ FILE __)));
// Database information
// Need hash
Define ("DB_USERNAME ","****");
Define ("DB_PASSWORD ",'*****');
Define ("DB_NAME", "blog ");
// Important directory
Define ("CLASS_PATH", "classes ");
Define ("TEMPLATE_PATH", "templates ");
// User imformation
Define ("ADMIN_USERNAME", "admin ");
Define ("ADMIN_PASSWORD", '$ 2a $08 $ wim8kpwHhAKa6MBSsGUMGOYfjkU1xvRKd4Fxwal. wj8dqFboCVSFawim8kpwHhAKa6MBSsGUMGO ');
// Hash and verified the password
Function hasher ($ info, $ encdata = false ){
$ Strength = "08 ";
// If encrypted data is passed, check it against input ($ info)
If ($ encdata ){
If (substr ($ encdata, 0, 60) = crypt ($ info, "$ 2a $ ". $ strength. "$ ". substr ($ encdata, 60 ))){
Return true;
} Else {
Return false;
}
} Else {
// Make a salt and hash it with input, and add salt to end
$ Salt = "";
For ($ I = 0; $ I <22; $ I ++ ){
$ Salt. = substr ("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand (0, 63), 1 );
}
// Return 82 char string (60 char hash & 22 char salt)
Return crypt ($ info, "$ 2a $". $ strength. "$". $ salt). $ salt;
}
}
Function _ autoload ($ className ){
If (file_exists (ROOT. DS. 'class'. DS. strtolower ($ className). '. class. php ')){
Require_once (ROOT. DS. 'classes '. DS. strtolower ($ className).'. class. php ');
} Else {
/* Error Generation Code Here */
}
}
Here we define some basic constants and several functions.
The _ autoload () function loads all classes in admin/class /.
The hasher () function is used to encrypt an 88-bit irreversible password. during login, the constant and hasher () function in config. php are used for verification.
Let's take a look at our admin/index. php background controller. The controller homepage displays some blog-related data.
The Code is as follows:
Require_once ("config/config. php ");
Session_start ();
$ Action = isset ($ _ GET ['action'])? $ _ GET ['action']: "";
$ Username = isset ($ _ SESSION ['username'])? $ _ SESSION ['username']: "";
If ($ action! = "Login" & $ action! = "Logout "&&! $ Username ){
Login ();
Exit;
}
Switch ($ action ){
Case "login ":
Login ();
Break;
Case "logout ";
Logout ();
Break;
Default:
Admin ();
Break;
}
Function login (){
$ Results ['pagetitle'] = "Login Form ";
// Handle login
If (isset ($ _ POST ['login']) {
// We simple verify it from constant variable
// If we need to verify the user from database, do this later
// $ User = new User;
// $ User-> isValidateUser ($ name, $ password );
If ($ _ POST ['username'] = ADMIN_USERNAME & $ _ POST ['Password'] = hasher ($ _ POST ['Password'], ADMIN_PASSWORD )){
// Register a session data
$ _ SESSION ['username'] = ADMIN_USERNAME;
// Location to admin page
Header ("Location: index. php ");
} Else {
// Login failed: display an error message to the user
$ Results ['errormessage'] = "Incorrect username or password. Please try again .";
Require (TEMPLATE_PATH. "/loginForm. php ");
}
} Else {
Require (TEMPLATE_PATH. "/loginForm. php ");
}
}
Function admin (){
$ Results ['pagetitle'] = "Administrator Page ";
Require (TEMPLATE_PATH. "/admin. php ");
}
Function logout (){
$ Results ['pagetitle'] = "Login Page ";
Unset ($ _ SESSION ['username']);
Header ("Location: index. php ");
}
This design model is learned from a foreigner!
The principle is:
First, we load our config. php, initialize the session variable, and obtain the value of $ action, an important variable;
Then we judge the values of $ action and $ username. If the user is not logged on and the user name is empty, return to the logon page;
If you have entered the user name and password correctly, register a session variable $ username and jump to the homepage index. php, then we will call the default $ action admin (), this function will load a template admin. php; there is an array variable $ results ['pagetitle'] and our background blog style framework.
If an error is entered, a prompt is displayed.
The core of this design concept is give {action} then {do something}
We will see it repeatedly in the code below.
This is the framework style of the blog background. It is copied from the blog garden and adopts the table layout. It is compatible and can be customized with other styles. It is simple, practical, and scalable, perfect background framework.
This style is also compatible with other browsers. I have completed some of the functions when I write this blog. Next article: Implement essays, articles, diaries, and CRUD for their classification.
Ps: these operations have not yet used ajax, because I am not familiar with ajax.