
Introduction to Sessions and Cookies
Authored by Joseph Andreas
Information Technology (IT)
University
Used 6+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
17 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the primary purpose of using sessions in PHP?
To store data on the server for a specific user
To track user preferences across multiple visits
To store large amounts of data permanently
To ensure that all users share the same data
Answer explanation
Sessions store user-specific data on the server across multiple requests, ensuring continuity for a user during their visit
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is a key difference between sessions and cookies?
Sessions store data on the client-side, whereas cookies store data on the server
Cookies expire after the browser is closed, while sessions persist indefinitely
Sessions are stored on the server, whereas cookies are stored on the client
Cookies cannot store user authentication details
Answer explanation
Sessions store data on the server and use a session ID to link the user, while cookies store data directly on the client’s browser
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What PHP function is used to start a session?
start_session()
session_begin()
session_start()
init_session()
Answer explanation
session_start() initializes a session and must be called before any output is sent to the browser
4.
MULTIPLE SELECT QUESTION
45 sec • 2 pts
Which of the following is TRUE about cookies?
They are stored in the client’s browser
They can store sensitive data securely
They can be accessed using $_COOKIE in PHP
They are deleted as soon as the user leaves the website
Answer explanation
Cookies are stored on the client’s browser and can be accessed in PHP using the $_COOKIE superglobal. However, they are not secure for storing sensitive data
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How can you set a cookie in PHP?
create_cookie('user', 'JohnDoe', time() + 3600);
setcookie('user', 'JohnDoe', time() + 3600, '/');
store_cookie('user', 'JohnDoe', time() + 3600);
cookie_set('user', 'JohnDoe', time() + 3600);
Answer explanation
setcookie() is the correct function to create a cookie, with parameters specifying the name, value, expiration time, and path
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How do you delete a cookie in PHP?
deletecookie('user');
setcookie('user', '', time() - 3600, '/');
remove_cookie('user');
unsetcookie('user');
Answer explanation
Setting the cookie’s expiration time to a past value removes it from the browser
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What function is used to destroy a session?
session_delete();
session_end();
session_unset(); session_destroy();
session_remove();
Answer explanation
session_unset() clears the session variables, and session_destroy() terminates the session
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?