Interview Questions for PHP Session

Interview Questions related session topic in php are asked by IT company for job as below.

1.What is a session in PHP?
PHP session is used to store data on server side and pass data from one page to another temporarily.
$_SESSION variable is used to define session in PHP.

2. Why Sessions are more secure than cookies?
sessions are more secure because data is stored on the server whereas cookies are stored on client side machine. If the browser sends cookies over unencrypted connections, it will be possible for hackers to eavesdrop on your connection and read the contents of your cookies.

3. What is the difference between a cookie and a session in PHP?
Sessions data is stored on the server whereas cookies data are stored on client side machine.
Sessions are more secure than cookies.

4. What is session variable in PHP?
session variable is used to store data and retrive data from server. $_SESSION is used to define session variable in PHP.

5.How to close session in php?
A PHP session can be destroyed by session_destroy() function.
If you want to destroy a single session variable then you can use unset() function to unset a session variable.

6.How to manage session in php?
session can be managed in php as below.

  • Initialize a session by session_start() function.
  • Assign session data into $_SESSION variable.
  • Access session data using $_SESSION variable.
  • Remove session data using unset() function.
  • Destroy all session variable by using session_destroy() function.
  • Also you can handle session using php.ini configuration file by setting session.save_handler, session.save_path, session.use_cookies, session.cookie_secure, session.use_only_cookies, session.name, session.auto_start, session.cookie_lifetime, session.cookie_path, session.cookie_domain, session.cookie_httponly, session.gc_probability, session.gc_maxlifetime, session.cache_limiter, session.cache_expire.

7. What is session id?
A session ID is a unique number that a Web site's server generates for a specific user for the duration of session time out. session id can be generated by session_id() function in php.

8. What is session timeout in php?
The default session time in PHP is 24 minutes (1440 seconds).
By default, a session in PHP gets destroyed when the browser is closed.

9. How to change session timeout in php?
A php.ini configuration file is used to change session timeout in php. We can set session timeout using session.gc_maxlifetime in php.ini file.

10. What is session.save_handler?
session.save_handler is configuration directive in php.ini file. By default, the value of session.save_handler is files.
This Handler used to store/retrieve data.
session.save_handler = files | mm | sqlite | user

11. What is default name of session in php?
PHPSESSID is the default name of session in php. You can specify the name of the session using session.name = PHPSESSID directive in php.ini file.

Comments

ashok modi

Great collection of Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

49563