Login Wall PHP Assignment

From Knowledge Kitchen
Jump to navigation Jump to search


Overview

Create a page that requires authentication.

  • Users must not be able to view the page unless they have already logged-in with the correct username and password.
  • Unauthenticated users who attempt to view the page should be redirected to a log in page.


Wireframes

Download an view the index.html file to see interactive wireframes for this assignment: File:Basic php authentication interactive prototype.zip


Details

There are 3 files necessary for this assignment:


Log in page

This is a simple HTML page with two input fields for username and password, and a submit button.

  • Once the user clicks the submit button, the browser should send the username and password that the user entered to the PHP authentication script.


PHP authentication script

The PHP script should receive the username and password that the browser sent along with the request, and compare them to a hard-coded username and password.

  • If the two do not match, the user should be redirected back to the Log in view.
  • If the two do match, the PHP script should set an authentication cookie that indicates that the user is logged in, and then redirect the browser to the Home view.


Home page

This page must enforce restricted access.

  • If a user who visits this page does not have the authentication cookie, they should be redirected to the Log in page.
  • If a user does have the authentication cookie, they should be allowed to view the page.


Extra credit

Once you complete the basics, you may decide that it doesn't make sense to allow a logged-in user to view the Log in page.

  • Add code that redirects to the Home page any logged-in user who attempts to view the Log in page.


Extra extra credit

If a user attempts to log in, but enters incorrect credentials, return them to the Log In page and show an error message saying, "Log in failed. Username or password incorrect."


Flow chart

This flow chart shows the various pages and action users can take to navigate among them. Note that this diagram includes the extra credit option whereby a user cannot view the Log In page if already logged in.

Basic php authentication assignment flow chart.png

Solution

Here is an attempt at a solution, in case you're totally stuck.