PHP Session Behavior

Changing Session Behavior

You can alter PHP's default session-handling behavior.

The php.ini file contains several configuration directives that you can alter:

DirectiveDescription
session.cookie_lifetimeHow long the session cookie should last for (in seconds). The default is zero, which expires the cookie when the browser is quit.
session.cookie_pathThe path field for the session cookie. Defaults to "/" which means the entire site.
session.cookie_domainThe domain field for the session cookie. Defaults to "" which means the current server.
session.cookie_httponlyThe HttpOnly field for the session cookie. Defaults to false.
session.auto_startDefaults to false . Change it to true , and PHP automatically starts a session the moment your script starts executing saving you from calling session_start().

You can either alter these directives directly in your php.ini file, or you can set them on a per - script basis using the ini_set() PHP function:


<?PHP
ini_set( "session.cookie_lifetime", 1200 );  
// Set session timeout to 20  minutes  
?>

Next chapter...

What you will learn in the next chapter:

  1. What is a HTML form
  2. Example - an example form
  3. Form attributes
  4. Example - Create an HTML Form
Home » PHP Tutorial » PHP Session
PHP Session
PHP Access Session Data
PHP Destroy Session
PHP Session Behavior