Sessions and Cookies Flashcards

1
Q

In PHP, sessions and cookies are two mechanisms used to ____ data, but they operate in different ways and serve different purposes.

A

store user-specific

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A session is a _______ mechanism that allows you to store user data across ____ pages during a user’s visit to a website

A

server-side storage
multiple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens when a session is initiated?

A

A unique session ID is generated & stored on server, sent to browser as a cookie.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Session data is stored on the server and can be accessed using the ____ superglobal array

A

$_SESSION

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

To start a session, you use the __ function at the beginning of your script.

A

session_start()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write a code for creating a session?

A

session_start(); // Start the session
$_SESSION[‘username’] = ‘JohnDoe’; // Store session variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the lifetime of a session?

A

Sessions are temporary and ends when browser is closed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Data stored in sessions is kept on the ___, which makes it more secure than cookies.

A

server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are cookies?

A

Cookies are small pieces of data stored on the client-side (the user’s browser), sent to server with each request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the lifetime of a cookie?

A

Persists until expiration date. If no expiration time is set, the cookie will be deleted when the browser is closed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Where are cookies stored?

A

On user’s device, making them less secure and unsuitable for sensitive info.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are cookies often used for?

A

Tracking user behavior, storing preferences, and maintaining sessions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly