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:
Directive | Description |
---|---|
session.cookie_lifetime | How long the session cookie should last for (in seconds). The default is zero, which expires the cookie when the browser is quit. |
session.cookie_path | The path field for the session cookie. Defaults to "/" which means the entire site. |
session.cookie_domain | The domain field for the session cookie. Defaults to "" which means the current server. |
session.cookie_httponly | The HttpOnly field for the session cookie. Defaults to false. |
session.auto_start | Defaults 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:
Home » PHP Tutorial » PHP Session