Professional Documents
Culture Documents
DWAP Session 13
DWAP Session 13
Objectives
Cookies:
Allow the website administrator to track the user’s browsing
patterns and activities on the website.
Are sent to a client computer along with the page output.
Can store data up to 4 KB.
A cookie:
Is a small text file that contains information and is stored in a Web
browser.
Is sent from the server in the Set-cookie field of the HTTP header.
For example:
Set-Cookie: username=James; expires=Friday, 05-
Jun-12 22:03:38 GMT;
path=/;
Has the following components:
Name
Value
Expires
Path
Domain
Answer:
The $_COOKIE global array is used for accessing the values
stored in a cookie.
Problem Statement:
The management at Global Electronics wants its employees to
access its website for handling the customers’ requests.
However, an employee needs to sign in before accessing the
content of the website. The sign in process requires the
employee to fill a login form, which contains user-specific
information, role, and username. The role should be selected
from the provided options, such as the user and admin, before
submitting the form. After submitting the form successfully, the
Welcome page should appear that displays the message,
"Welcome <user name>".
Create a PHP application to perform this task.
Solution:
To create the PHP application that verifies the username and
password and redirects the user according to the role, you
need to perform the following tasks:
Create the Login form.
Create the Validate file.
Create the Home file.
Create the Admin file.
Execute the application and verify the output.
session_start():
Enables you to create a session.
Must be called before the <html> tag.
For example:
<?php session_start(); ?>
<html>
<body>
</body>
</html>
session_destroy():
Enables you to destroy a session.
Syntax:
bool session_destroy()
For example:
<?php
session_destroy();
?>
Answer:
The session_start() function is used to create a session.
Problem Statement:
You need to create a Web application for GlobalToyz store that
sells toys online. Topurchase toys from the company’s website,
a user needs to login. When the user is logged in successfully,
details should be stored into a session and the user should be
redirected to the page where the user name and list of available
toys are displayed. When the user selects the toy name, the toy
description and price of the toy should be displayed. In addition,
the text field should be displayed asking for the required
quantity of toys. After entering the required quantity, when the
user submits the form, all the details of the user and the toy
should get stored in a session. The stored information will be
displayed to the user with the amount of the toys to be paid.
When the user logs out, the session expires.
Create a PHP application to perform this task.
Solution:
To create the PHP application that validates the user name
and password entered by the user and then facilitates the user
to select the toy, you need to perform the following tasks:
Create the Login form.
Create the Validate file.
Create the Home file.
Create the Show file.
Create the Details file.
Create the Message file.
Create the Logout file.
Execute the application and verify the output.