Activity: PHP state maintenance (hidden input and URL rewriting)
(no submission)
Purpose:
- Hands-on experience with PHP state maintenance, using form hidden input and URL rewriting
- Practice PHP form handling
- Practice PHP file processing
- Get ready to work on your assignment (course project)
For this exercise, you may work alone or with another student in this course.
Write PHP program(s) to perform the following tasks.
We'll stop periodically, and do exercise one step at a time with discussion between steps
You may use your form handling program from POTD 3
as a starting point.
Alternatively, you may create a login page and a form handling page from scratch.
On the login page
- Write code to keep track of the number of failed login attempts.
Make use of a form hidden input and URL rewriting to maintain the state of the application.
Reminder: Because of the HTTP stateless property,
we need to maintain state by passing tokens between HTTP request/response cycles.
-
If a user fails to login multiple times (assume that we allow 3 attempts),
disable the login page.
One simple solution is to disable the login button.
You may choose to implement a more sophisticated behavior to disable the login.
- If the login is successful, pass along the user's name and redirect the user to the form
allowing the user to submit his/her comment or request.
On the comment page
- Write code to check if the user has logged in.
If the user has not logged in, redirect the user to the login page (i.e., enforce login).
- Write code to retrieve the user's name.
Display a greeting message with the user's name.
You decide on the content and format of the greeting message,
and the location where it will be displayed.
Pre-fill the Name input of the form with the user's name.
- Perform a server-side input validation to ensure that all
form inputs are entered.
If any form input is missing, display a proper message.
- If all form inputs are entered, display a confirmation message.
You decide on the content and format of the confirmation,
and the location where it will be displayed.
- If all form inputs are entered,
write the user's data entry to a data file
(you decide on the data format and the file format).
To deploy and test your program
use one of the following options:
Copyright © 2022 Upsorn Praphamontripong
Released under the
CC-BY-NC-SA 4.0 license.
Last updated 2022-05-29 14:29