Task 8 - Cookies Programming Tasks for Practice using PHP


Before doing below listed tasks, understand what are cookies and how they work. Then understand my given code samples. Note that, below tasks are just to understand the cookies, it may not appear in real applications.

Here are the tasks:

1. Make interval.php that saves a cookie in user internet browser with current time. When user access the page again, show the duration in seconds after which the page is opened.

2. Make a form with two input text fields. First for cookie name and other for cookie value, when user submit the form. Create new cookie with passed name and value. 

3. Make a form with one input text field and Delete Cookie button, when user submit the form, delete only the cookies whose name is submitted by form. Must handle form using Postback mechanism.

4. Make show-all-cookies.php page, it should display all cookies the application has stored in user browser. (assume, you don't know the keys).

5. Create control-panel.php to manage, view and create cookies. User shall use it to view and update cookies' names and values.  This form must be dynamic, that means, if there are 10 cookies received from browser, you must make 10 input text fields for cookie names and 10 for cookies values and so on ... If user set the value field empty, that cookie shall be deleted from browser.
At end of form, add two text input fields to be used to add a new cookie by entering its key and value, e.g.
  1. Enter New  Cookie Key : _______________
  2. Enter Cookie Value:          _______________
Male a login.php page that shall take user-name and password i.e. admin and test. If user enters, correct user name, redirect user to control-panel.php, if credentials are incorrect, show same login.php page with error message whether the user-name was incorrect or password. After successful login, before redirecting, save some key in cookie to keep record, user has entered correct user-name/password. When user fetches control-panel.php directly, make sure whether the user is login, checking the cookie. If user is not login, redirect to login.php page. 

Comments