First Graded Assignment Ctec 227 Lab 2 Instructions

ctec-227-lab-2-instructions

ctec-227-lab-2-instructions

ctec-227-lab-2-instructions

ctec-227-lab-2-instructions

ctec-227-lab-2-instructions

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 2

DownloadFirst Graded Assignment Ctec-227-lab-2-instructions
Open PDF In BrowserView PDF
Clark College
CTEC 227 PHP with SQL II
Document Type:

Lab No. 2

Document Name:

Using Cookies

setcookie Syntax
setcookie(name,value,expire,path,domain,secure)
Parameter
name
value
expire

path

domain

secure

Description
Required.
Specifies the name of the cookie
Required.
Specifies the value of the cookie
Optional.
Specifies when the cookie expires.
time()+3600*24*30 will set the cookie to expire in 30 days. If this
parameter is not set, the cookie will expire at the end of the session
(when the browser closes).
Optional.
Specifies the server path of the cookie.
If set to "/", the cookie will be available within the entire domain. If
set to "/test/", the cookie will only be available within the test
directory and all sub-directories of test. The default value is the
current directory that the cookie is being set in.
Optional.
Specifies the domain name of the cookie.
To make the cookie available on all subdomains of example.com
then you'd set it to ".example.com". Setting it to www.example.com
will make the cookie only available in the www subdomain
Optional.
Specifies whether or not the cookie should only be transmitted over
a secure HTTPS connection. TRUE indicates that the cookie will
only be set if a secure connection exists. Default is FALSE.

In this lab exercise students will learn how to set and read cookies from PHP.
1. Create a PHP script called cookie_bake.php.
2. On this page set the following cookies as follows:
a. “username” to “BettyW” with an expiration two hours (time() + 7200)
b. “firstname” to “Betty” with an expiration of two hours (time() + 7200)
c. “lastname” to “White” with an expiration of two hours (time() + 7200)
d. Now set up 3 cookies using an array cookie:
i. setcookie("cookie[institution]","Clark", time() + 7200);
ii. setcookie("cookie[city]","Vancouver", time() + 7200);
iii. setcookie("cookie[state]","WA", time() + 7200);
Cookies

Page 1 of 2

Clark College
CTEC 227 PHP with SQL II
3. Now create a PHP script called ccookie_eat.php.
4. In the this script echo the value of each cookie using $_COOKIE[]
5. For the array cookie use the following code to echo out the values of the cookies:
if (isset($_COOKIE["cookie"])){
foreach ($_COOKIE["cookie"] as $key=>$val) {
echo $key.' is '.$val."
\n"; } // end foreach } // end if 6. Open the page up to set the cookies. 7. Now open up Chrome developer tools to ensure that your cookies were set correctly. 8. Create a PHP script called cookie_monster.php. 9. The cookie_monster script will be used to delete the cookies you created above. 10. To delete cookies simply set the expiration time to a time in the past. Try using time() – 3600. 11. Now run your cookie_monster.php script to delete the cookies. 12. Using the Chrome developer tools check to see that your cookies were successfully deleted. Cookies Page 2 of 2

Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.7
Linearized                      : No
Page Count                      : 2
Language                        : en-US
Tagged PDF                      : Yes
XMP Toolkit                     : 3.1-701
Title                           : First Graded Assignment
Creator                         : Clark College
Creator Tool                    : Microsoft Word
Create Date                     : 2019:04:01 02:16:30+00:00
Modify Date                     : 2019:04:01 02:16:30+00:00
Document ID                     : uuid:B513006A-1888-43D4-A8BC-055AE8835FB9
Instance ID                     : uuid:B513006A-1888-43D4-A8BC-055AE8835FB9
Author                          : Clark College
EXIF Metadata provided by EXIF.tools

Navigation menu