PHP Multiple Choice Questions – Session Handling

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Session Handling”.

1. Which one of the following is the very first task executed by a session enabled page?
a) Delete the previous session
b) Start a new session
c) Check whether a valid session exists
d) Handle the session
View Answer

Answer: c
Explanation: The session variables are set with the PHP global variable which is $_SESSION. The very first task executed by a session enabled page is Check whether a valid session exists.

2. How many ways can a session data be stored?
a) 3
b) 4
c) 5
d) 6
View Answer

Answer: b
Explanation: Within flat files(files), within volatile memory(mm), using the SQLite database(sqlite), or through user defined functions(user).

3. Which directive determines how the session information will be stored?
a) save_data
b) session.save
c) session.save_data
d) session.save_handler
View Answer

Answer: d
Explanation: The class SessionHandler is used to wrap whatever internal save handler is set as defined by the session.save_handler configuration directive which is usually files by default.

advertisement
advertisement

4. Which one of the following is the default PHP session name?
a) PHPSESSID
b) PHPSESID
c) PHPSESSIONID
d) PHPIDSESS
View Answer

Answer: a
Explanation: You can change this name by using the session.name directive.

5. If session.use_cookie is set to 0, this results in use of _____________
a) Session
b) Cookie
c) URL rewriting
d) Nothing happens
View Answer

Answer: c
Explanation: The URL rewriting allows to completely separate the URL from the resource. URL rewriting can turn unsightly URLs into nice ones with a lot less agony and expense than picking a good domain name. It enables to fill out your URLs with friendly, readable keywords without affecting the underlying structure of pages.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. If the directive session.cookie_lifetime is set to 3600, the cookie will live until ____________
a) 3600 sec
b) 3600 min
c) 3600 hrs
d) the browser is restarted
View Answer

Answer: a
Explanation: The lifetime is specified in seconds, so if the cookie should live 1 hour, this directive should be set to 3600.

7. Neglecting to set which of the following cookie will result in the cookie’s domain being set to the host name of the server which generated it.
a) session.domain
b) session.path
c) session.cookie_path
d) session.cookie_domain
View Answer

Answer: d
Explanation: The directive session.cookie_domain determines the domain for which the cookie is valid.
advertisement

8. What is the default number of seconds that cached session pages are made available before the new pages are created?
a) 360
b) 180
c) 3600
d) 1800
View Answer

Answer: b
Explanation: The directive which determines this is session.cache_expire.

9. What is the default time(in seconds) for which session data is considered valid?
a) 1800
b) 3600
c) 1440
d) 1540
View Answer

Answer: c
Explanation: The session.gc_maxlifetime directive determines this duration. It can be set to any required value.
advertisement

10. Which one of the following function is used to start a session?
a) start_session()
b) session_start()
c) session_begin()
d) begin_session()
View Answer

Answer: b
Explanation: A session is started with the function session_start() . The session variables are set with the PHP global variable which is $_SESSION.

More MCQs on PHP Session Handling:

Sanfoundry Global Education & Learning Series – PHP Programming.

To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.