The behaviour of these functions is affected by settings in php.ini.
Name | Default | Changeable | Changelog |
---|---|---|---|
session.save_path | "" | PHP_INI_ALL | |
session.name | "PHPSESSID" | PHP_INI_ALL | |
session.save_handler | "files" | PHP_INI_ALL | |
session.auto_start | "0" | PHP_INI_PERDIR | |
session.gc_probability | "1" | PHP_INI_ALL | |
session.gc_divisor | "100" | PHP_INI_ALL | |
session.gc_maxlifetime | "1440" | PHP_INI_ALL | |
session.serialize_handler | "php" | PHP_INI_ALL | |
session.cookie_lifetime | "0" | PHP_INI_ALL | |
session.cookie_path | "/" | PHP_INI_ALL | |
session.cookie_domain | "" | PHP_INI_ALL | |
session.cookie_secure | "" | PHP_INI_ALL | |
session.cookie_httponly | "" | PHP_INI_ALL | Available since PHP 5.2.0. |
session.cookie_samesite | "" | PHP_INI_ALL | Available since PHP 7.3.0. |
session.use_strict_mode | "0" | PHP_INI_ALL | Available since PHP 5.5.2. |
session.use_cookies | "1" | PHP_INI_ALL | |
session.use_only_cookies | "1" | PHP_INI_ALL | |
session.referer_check | "" | PHP_INI_ALL | |
session.cache_limiter | "nocache" | PHP_INI_ALL | |
session.cache_expire | "180" | PHP_INI_ALL | |
session.use_trans_sid | "0" | PHP_INI_ALL | |
session.trans_sid_tags | "a=href,area=href,frame=src,form=" | PHP_INI_ALL | Available since PHP 7.1.0. |
session.trans_sid_hosts | $_SERVER['HTTP_HOST'] | PHP_INI_ALL | Available since PHP 7.1.0. |
session.sid_length | "32" | PHP_INI_ALL | Available since PHP 7.1.0. |
session.sid_bits_per_character | "5" | PHP_INI_ALL | Available since PHP 7.1.0. |
session.upload_progress.enabled | "1" | PHP_INI_PERDIR | Available since PHP 5.4.0. |
session.upload_progress.cleanup | "1" | PHP_INI_PERDIR | Available since PHP 5.4.0. |
session.upload_progress.prefix | "upload_progress_" | PHP_INI_PERDIR | Available since PHP 5.4.0. |
session.upload_progress.name | "PHP_SESSION_UPLOAD_PROGRESS" | PHP_INI_PERDIR | Available since PHP 5.4.0. |
session.upload_progress.freq | "1%" | PHP_INI_PERDIR | Available since PHP 5.4.0. |
session.upload_progress.min_freq | "1" | PHP_INI_PERDIR | Available since PHP 5.4.0. |
session.lazy_write | "1" | PHP_INI_ALL | Available since PHP 7.0.0. |
url_rewriter.tags | "a=href,area=href,frame=src,form=" | PHP_INI_ALL | Since PHP 7.1.0, this INI is no longer used by session. |
session.hash_function | "0" | PHP_INI_ALL | Removed in PHP 7.1.0. |
session.hash_bits_per_character | "4" | PHP_INI_ALL | Removed in PHP 7.1.0. |
session.entropy_file | "" | PHP_INI_ALL | Removed in PHP 7.1.0. |
session.entropy_length | "0" | PHP_INI_ALL | Removed in PHP 7.1.0 |
session.bug_compat_42 | "1" | PHP_INI_ALL | Removed in PHP 5.4.0. |
session.bug_compat_warn | "1" | PHP_INI_ALL | Removed in PHP 5.4.0. |
The session management system supports a number of configuration options which you can place in your php.ini file. We will give a short overview.
session.save_handler
string
session.save_path
string
There is an optional N argument to this directive that determines the number of directory levels your session files will be spread around in. For example, setting to '5;/tmp' may end up creating a session file and location like /tmp/4/b/1/e/3/sess_4b1e384ad74619bd212e236e52a5a174If . In order to use N you must create all of these directories before use. A small shell script exists in ext/session to do this, it's called mod_files.sh, with a Windows version called mod_files.bat. Also note that if N is used and greater than 0 then automatic garbage collection will not be performed, see a copy of php.ini for further information. Also, if you use N, be sure to surround session.save_path in "quotes" because the separator (;) is also used for comments in php.ini.
The file storage module creates files using mode 600 by default. This default can be changed with the optional MODE argument: N;MODE;/path where MODE is the octal representation of the mode. Setting MODE does not affect the process umask.
If you leave this set to a world-readable directory, such as /tmp (the default), other users on the server may be able to hijack sessions by getting the list of files in that directory.
When using the optional directory level argument N, as described above, note that using a value higher than 1 or 2 is inappropriate for most sites due to the large number of directories required: for example, a value of 3 implies that (2 ** session.sid_bits_per_character) ** 3 directories exist on the filesystem, which can result in a lot of wasted space and inodes.
Only use N greater than 2 if you are absolutely certain that your site is large enough to require it.
Note: Prior to PHP 4.3.6, Windows users had to change this variable in order to use PHP's session functions. A valid path must be specified, e.g.: c:/temp.
session.name
string
session.auto_start
boolean
session.serialize_handler
string
session.gc_probability
integer
session.gc_divisor
integer
session.gc_maxlifetime
integer
Note: If different scripts have different values of session.gc_maxlifetime but share the same place for storing the session data then the script with the minimum value will be cleaning the data. In this case, use this directive together with session.save_path.
session.referer_check
string
session.entropy_file
string
Note: Removed in PHP 7.1.0. As of PHP 5.4.0 session.entropy_file defaults to /dev/urandom or /dev/arandom if it is available. In PHP 5.3.0 this directive is left empty by default.
session.entropy_length
integer
session.use_strict_mode
boolean
Note: Enabling session.use_strict_mode is mandatory for general session security. All sites are advised to enable this. See session_create_id() example code for more details.
Note: The expiration timestamp is set relative to the server time, which is not necessarily the same as the time in the client's browser.
session.cache_limiter
string
session.cache_expire
integer
session.use_trans_sid
boolean
Note: URL based session management has additional security risks compared to cookie based session management. Users may send a URL that contains an active session ID to their friends by email or users may save a URL that contains a session ID to their bookmarks and access your site with the same session ID always, for example. Since PHP 7.1.0, full URL path, e.g. https://php.net/, is handled by trans sid feature. Previous PHP handled relative URL path only. Rewrite target hosts are defined by session.trans_sid_hosts.
Note: Before PHP 7.1.0, url_rewriter.tags was used for this purpose. Since PHP 7.1.0, fieldset is no longer considered as special tag.
session.trans_sid_hosts
string
session.bug_compat_42
boolean
Note: Removed in PHP 5.4.0.
session.bug_compat_warn
boolean
Note: Removed in PHP 5.4.0.
session.sid_length
integer
Compatibility Note: Use 32 for session.hash_func=0 (MD5) and session.hash_bits_per_character=4, session.hash_func=1 (SHA1) and session.hash_bits_per_character=6. Use 26 for session.hash_func=0 (MD5) and session.hash_bits_per_character=5. Use 22 for session.hash_func=0 (MD5) and session.hash_bits_per_character=6. You must configure INI values to have at least 128 bits in session ID. Do not forget set appropriate value to session.sid_bits_per_character, otherwise you will have weaker session ID.
Note: This setting is introduced in PHP 7.1.0.
session.sid_bits_per_character
integer
Note: This setting is introduced in PHP 7.1.0.
session.hash_function
mixed
Since PHP 5.3.0 it is also possible to specify any of the algorithms provided by the hash extension (if it is available), like sha512 or whirlpool. A complete list of supported algorithms can be obtained with the hash_algos() function.
Note: This setting was introduced in PHP 5. Removed in PHP 7.1.0.
session.hash_bits_per_character
integer
Note: Removed in PHP 7.1.0.
session.upload_progress.enabled
boolean
session.upload_progress.cleanup
boolean
Note: It is highly recommended to keep this feature enabled.
session.upload_progress.prefix
string
session.upload_progress.name
string
session.upload_progress.freq
mixed
session.upload_progress.min_freq
integer
session.lazy_write
boolean
The register_globals configuration settings influence how the session variables get stored and restored.
Upload progress will not be registered unless session.upload_progress.enabled is enabled, and the $_POST[ini_get("session.upload_progress.name")] variable is set. See Session Upload Progress for more details on this functionality.