Control Panel

In this step you'll start building a control panel for your blog site. It will require a login, so that only authenticated users can acces to the control panel. Eventually you'll build pages that allow you to add/edit blog posts, upload files, and a few other things that will allow you to manage your blog site. But in this step, you'll just focus the login screen and authentication code. It will be a crude and simple approach, but in Advanced Topics (next semester) we'll discuss other ways of authenticating users.

Pre-Reqs

Setting Up the Control Panel

  1. Create a folder inside the my-new-site folder named control-panel
  2. Inside the control-panel folder, create a file named login.php. The login page should start out by looking like this.
    Notice the following:
  3. Open the login page in the browser. The form on the page is not pretty, but it will do for now.
  4. Add an IF statement just under the $pageTitle and $pageDescription variables. The code should look like this. Note that this IF statement checks to see if the login form was POSTED. If it was, then it extracts the user name and password entered. Finally it checks the user input to see if it matches the real user name and password for logging in. This is a crude authentication system, but it's simple.
  5. By the way, here is some info about the Null Coalesce operator, which was introduced in PHP 7.
  6. Refresh the page in the browser and try it out. Note that if you enter the proper user name and password, you'll be redirected to a page that we have not yet created (the control panel home page). Also note what happens if you don't enter the proper username and password.
  7. Important - there are some security risks with displaying the password in our code as we have. If our PHP installation gets corrupted, the web server could display PHP code in the browser. We could make things more secure by hashing the password and storing it in a folder that is outside of the doc root directory.

Create the Control Panel Home Page

Making use of Sessions

Checking to see if a user has been authenticated (logged in)

We will now create an include file that will be included in the control panel home page (the reason why we are putting this code into an include file is that it will be used by other pages in the control panel as well). It will verify that the user has been authenticated by checking our session variable. If the session variable has not been set, then we'll redirect the user to the login page. This will prevent people from seeing the control panel home page if they have not logged in.

Update the Nav Bar

Security Issues

Here are some things we can do to help secure the password (we'll discuss in class)

Follow Up Questions: