Introduction to Sessions and Cookies

Introduction to Sessions and Cookies

University

17 Qs

quiz-placeholder

Similar activities

Сервлеттер туралы тест

Сервлеттер туралы тест

University

14 Qs

User Experience (UX) & Usability

User Experience (UX) & Usability

University

15 Qs

Quiz8 Web E

Quiz8 Web E

University

21 Qs

Chapter 7 part 1 -Design of Forms and Reports

Chapter 7 part 1 -Design of Forms and Reports

University

20 Qs

CP1 Quiz

CP1 Quiz

University

16 Qs

ICT G7 Chapter 2.2 Direct Data Entry Devices

ICT G7 Chapter 2.2 Direct Data Entry Devices

7th Grade - University

15 Qs

Cloud Computing Quiz

Cloud Computing Quiz

12th Grade - University

15 Qs

CLC Unit 2 Lesson 5,6 & 7 Quiz

CLC Unit 2 Lesson 5,6 & 7 Quiz

University

12 Qs

Introduction to Sessions and Cookies

Introduction to Sessions and Cookies

Assessment

Quiz

Information Technology (IT)

University

Easy

Created by

Joseph Andreas

Used 6+ times

FREE Resource

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

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?