Which function is used to start a session in PHP?
Analysis & Theory
`session_start()` initializes a new session or resumes an existing one.
Which PHP superglobal is used to store session variables?
Analysis & Theory
`$_SESSION` is used to store and retrieve session variables.
What happens if `session_start()` is not called before using `$_SESSION`?
B
Error: Cannot use session variables before starting session
C
Session is automatically started
Analysis & Theory
`session_start()` must be called before using `$_SESSION` or setting session variables.
Which function is used to destroy all session data?
Analysis & Theory
`session_destroy()` destroys all data associated with the current session.
What happens if you close the browser without destroying the session?
A
Session ends immediately
B
Session continues until the server timeout
D
Session gets deleted from server
Analysis & Theory
Closing the browser removes the session ID cookie, but the session on the server persists until timeout.
Where does PHP store session data by default?
Analysis & Theory
Session data is stored on the server; only the session ID is stored in the client browser.
Which function can remove a single session variable?
C
unset($_SESSION['var'])
Analysis & Theory
Use `unset($_SESSION['var'])` to remove a specific session variable.
What does `session_unset()` do?
A
Destroys the session completely
B
Removes all session variables but keeps the session ID
C
Ends the session and deletes session files
Analysis & Theory
`session_unset()` frees all session variables without ending the session itself.
Which statement is true about sessions compared to cookies?
A
Sessions are stored on the client side
B
Sessions can store more secure and larger data on the server
C
Sessions require no server storage
D
Cookies are safer than sessions
Analysis & Theory
Sessions are stored on the server, are safer for sensitive data, and can hold larger amounts of information than cookies.
What is the role of the session ID in PHP sessions?
A
It stores session variables
B
It links the user to their session data on the server
C
It encrypts the session data
D
It is the session file itself
Analysis & Theory
The session ID is stored in a cookie and is used to associate a user with their session data on the server.