PHP has several configuration directives to control session handling processes like session upload and URL rewriting. These are set with PHP configuration file php.ini. To know the values that are set we can use the phpinfo() function.
In this PHP tutorial, we are going to see about few important session configuration directives and their possible values.
session.save_handler = files | mm | sqlite | user
session.save_path = "N;/path"
where N is an Integer representing the depth of the subdirectory.
session.save_path = "N;MODE;/path"
where MODE is an Octal value. The default mode is 600 (allows the owner to read and write).
This directive has 1 or 0 as its value to specify whether cookies are used to store session id or not.
session.use_cookies = 0 | 1
If 1 then cookies will be used to store session id. If not, the session id is preserved by using URL rewriting.
It controls whether cookies are sent via secure connections or not. It will be set with ON | OFF values. The default is OFF.
By setting this directive cookies are used as the mandatory storage to preserve session id. It prevents session hijacking.
To specify the name of the session. PHPSESSID is the default name.
session.name = PHPSESSID
We need to start the session before using PHP session function. This directive is used to start the session automatically on each page request. So, we need to set session.auto_start as 1.
session.auto_start = 0 | 1
If session.auto_start is 1, managing objects into session need further configuration. That is, the auto_prepend_file directive is used to refer corresponding class.
This is used to set cookie lifetime. If it is set as 0, then cookie remains until browser restart.
To specify the path where the cookies will be valid.
Similarly, to specify the domain in which the cookies will be valid.
This directive is on then it will stop client side scripts to access session id preserved in cookies.
The values of these directives are used to calculate the probability of running garbage collection to clean up session data.
It has the max lifetime of the session id in seconds. If the session id reaches this limit, PHP will treat it as garbage and clear it.
This directive controls cache headers sent to the client and proxies. The possible values are,
session.cache_expire = 120
This directive is used to preserve session id by URL rewriting. As URL are shared among multiple users, maintaining session id in URL is risky. It causes multiple access with the same session_id at a time.
This directive is used to choose the hash function to generate session id. 0 and 1 represents MD5 and SHA algorithms respectively.