PHP Session MCQs
PHP Session MCQs : This section focuses on "Session" in PHP. These Multiple Choice Questions (mcqs) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. A _________ is a way to store information (in variables) to be used across multiple pages.
A. cookies
B. filters
C. session
D. exception
View Answer
Ans : C
Explanation: A session is a way to store information (in variables) to be used across multiple pages.
2. A session is started with the __________function.
A. session_first()
B. session_start()
C. session()
D. session_begin()
View Answer
Ans : B
Explanation: A session is started with the session_start() function.
3. _______ session variables stored by default in PHP?
A. Server Side
B. In Cookies
C. Client Side
D. None of the above
View Answer
Ans : A
Explanation: Server Side session variables stored by default in PHP.
4. Which of the following is used to destroy a PHP session?
A. destroy_session()
B. session_destroy()
C. stop_session()
D. end_session()
View Answer
Ans : B
Explanation: session_destroy() is used to destroy a PHP session.
5. By default, how long does a PHP session last?
A. 24 hours
B. 1 week
C. Until the browser is closed
D. Never
View Answer
Ans : C
Explanation: Until the browser is closed a PHP session last.
6. Which of the following is a valid session ID in PHP?
A. 1234567890abcdef
B. session_id_123
C. A session ID can be any string
D. All of the above
View Answer
Ans : D
Explanation: All of the above is a valid session ID in PHP.
7. How to remove all global session variables?
A. session_unset()
B. session_reset()
C. session_end()
D. session_kill()
View Answer
Ans : A
Explanation: To remove all global session variables, use session_unset()
8. How to destroy the session?
A. session_reset()
B. session_destroy()
C. session_end()
D. session_kill()
View Answer
Ans : B
Explanation: To destroy the session, use session_destroy()
9. Which of the following is the default name of the session cookie in PHP?
A. PHP_SESSION
B. session_id
C. PHPSESSID
D. session_cookie
View Answer
Ans : C
Explanation: PHPSESSID is the default name of the session cookie in PHP.
10. Regenerating the session ID after authentication methods can prevent session fixation attacks in PHP.
A. TRUE
B. FALSE
C. Can be true or false
D. None of the above
View Answer
Ans : A
Explanation: Regenerating the session ID after authentication methods can prevent session fixation attacks in PHP.
Discussion