Step by step teach you to use Php+mysql to build a website No.3 admin page

Source: Internet
Author: User

Let's take a look at what this blog will cover.

Our homepage has been set up, and then most of the content on the left side of the navigation can be clicked, leaving only "search" and "I m a writer" two links.

After this tutorial, we will be able to complete the following functions:

This is our main interface.


Click "I ' m a Writer":


Click on any of the links:


Writers post-Login page:



Well, let's take one step at a pace:

We can see in the main interface the form item inside, click I ' m a writer after the link is like this:


"admin/index.php", so we need to create a new folder on the host, named Admin, and then edit index.php, which is the page we are going to use for the author login today.

To facilitate the explanation, from now on, if you do not add special instructions, all the files are in the Admin folder under the new, we will review the directory structure:


Next, we will start the development of the author page!

index.php


This page is very simple, from the beginning of the picture is also seen, that is, two lines of the contents of the form, a link to this article to explain the writer.php, another link to publish.php.

Next, let's see.

writer.php



Let's start with a holistic look at how writer.php is doing what we want, and then some of the functions that appear inside are explained in more detail later.

Line 4th

Include a new file include_fns.php, note that this is also in the Admin folder, OH, writer.php will use a number of functions, and these functions, are from this Include_ Included in the fns.php.

Line 6th

Judging the current time a user login, this function will be included in the previously referenced file. If no user is logged in, then execute the login_form () function, display the user login form, otherwise, will display the current logged in user's article information

Line 13th

The Get_writer_record function is used to return information about the user, and then in 15-19 rows, in combination with the user's information, displays the line content:


21-23 rows

This SELECT statement should be very simple, that is, the current user published articles are found, follow the creation of the time to do a flashback sort

25-28 rows

According to the user's record, show the user A total of several articles, and then accompanied by a new link to add the article page story.php, which we explain in the next blog


30-59 rows

The contents of this should not be difficult for us to understand, before there is similar content, is to follow the search out the article information, display to the user, while providing a few links can do more:edit (story.php), delete (delete_story.php) and keywords (keyword.php) , etc.

Well, the whole framework here is clear, so let's take a look at a couple of new functions.


Let's see.

include_fns.php


Actually very simple right, here still introduced two new PHP files, one is the db_fns.php in the previous level directory, this we are already familiar in the previous article, is used for database link and operation of each function, note that the introduction of the format is:. /db_fns.php;

The other is our series of function user_auth_fns.phpabout the user.


Check_auth_user () function

This function appears in the user_auth_fns.php file:


Very simple, not much introduction.


login_form () function

is still in the user_auth_fns.php file:


This function is still not difficult, but also appeared before the content, is a form of input, and then click the Login button, the request is the login.php page, the way to send is post.

login.php page is still very simple, let's look at it:

login.php


Here are two key points:

1 is the login function, and this function is still from the user_auth_fns.php file:


We according to the two parameters passed username and password, are the previous user input content, and then go to the database inside and writers table inside to do the comparison, if found, the user entered the user name and password is legal, return 1; otherwise return 0.

2

We see the header (' Location: '. $_server[' http_referer '); the function is to return to the previous page and refresh the login;

The previous page is writer.php, because the user has already logged in, so in writer.php the first if judgment, the conclusion is that there are already logged users, so jump to 11 lines, the user article display page.


OK, let's go on to see:

Get_writer_record function

Because it is a database-level operation, this function is stored in the db_fns.php , note that this file is in the previous level directory OH



That's basically what it's about. Here, we have completed a total user login, display articles and other pages of the operation, this section of the content is a bit more, we have a good digestion. There are different messages that can be discussed together.




Step by step teach you to use Php+mysql to build a website No.3 admin page

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.