Project 1
Please solve it at a beginner level and provide all the necessary codes and all the steps required for it.
Everything step by step.
15.6.3 Hands-On Practice
PROJECT 1: Cookies
DIFFICULTY LEVEL: Intermediate Overview Demonstrate your ability to work with Cookies in PHP. You will create and read both persistent and session cookies, as shown in Figure 15.18.
15.6 Chapter Summary
809
Choose values and then create persistent and session cookies.
Read the value of the two cookies should be available
If you close the browser and then reopen this page, the session
Use this button to remove cookies for easier testing FIGURE 15.18 Completed Project 1
CHAPTER 15 Managing State
Instructions 1. You have been provided with a starting file named ch15-proj1.php along with a second page named other-page-php. The first file will be used to create the cookies as well as read them; the second page will verify that the cookies are available across other pages in the same domain. Examine the form element in ch15-proj1.php and note that the action is a file named make-cookies.php. 2. Create a new file named make-cookies.php. This file will contain no markup: it will just save the form data (the values of the two <select> lists) as cookie values. 3. After checking for the existence of the relevant form data, save the theme value as a persistent cookie using the setcookie() function. Set the expiry to be a day from the current time. You may need to set the domain value, which is the fifth parameter to the setcookie() function. Save the philosopher value as a session cookie by setting the expiry to 0. After setting the cookies, redirect back to chapter15-project1.php using a header(Location: chapter15-project1.php) function call. 4. Within the Reading the Cookie card in chapter15-project1.php, read and display the contents of these two cookies. Be sure to display an appropriate message if the cookies are not available (see Figure 15.18). 5. Add the same read and display cookie code to other-page.php. Notice that the link for Remove Cookies is for a file named remove-cookie.php. 6. Create a new file named remove-cookie.php. This file will contain no markup: it will just remove the cookies. To do this, use the unset() function on the two cookie values within the $_cookies array. Also, use the setcookie() function but with an expiry date in the past. Afterwards, redirect to ch15-proj1.php. Guidance and Testing 1. You may need to close the browser entirely to test your session cookies.