session.save_handler defines the name of the
handler which is used for storing and retrieving data
associated with a session. Defaults to
files. Note that individual extensions may register
their own save_handlers; registered handlers can be
obtained on a per-installation basis by referring to
phpinfo(). See also
session_set_save_handler().

session.save_path defines the argument which
is passed to the save handler. If you choose the default files
handler, this is the path where the files are created. See also
session_save_path().

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.

Warning

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.

Caution

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 64^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.serialize_handler defines the name of
the handler which is used to serialize/deserialize data. PHP
serialize format (name php_serialize), PHP
internal formats (name php and
php_binary) and WDDX are supported (name
wddx). WDDX is only available, if PHP is
compiled with WDDX
support. php_serialize is available
from PHP 5.5.4. php_serialize uses plain
serialize/unserialize function internally and does not have
limitations that php
and php_binary have. Older serialize handlers
cannot store numeric index nor string index contains special
characters (| and !) in
$_SESSION. Use php_serialize to avoid numeric
index or special character errors at script shutdown. Defaults
to php.

session.gc_divisor coupled with
session.gc_probability defines the probability
that the gc (garbage collection) process is started on every session
initialization.
The probability is calculated by using gc_probability/gc_divisor,
e.g. 1/100 means there is a 1% chance that the GC process starts
on each request.
session.gc_divisor defaults to 100.

session.gc_maxlifetime specifies the number
of seconds after which data will be seen as 'garbage' and
potentially cleaned up. Garbage collection may occur during session start
(depending on session.gc_probability and
session.gc_divisor).

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.

Note:
If you are using the default file-based session handler, your
filesystem must keep track of access times (atime). Windows FAT does
not so you will have to come up with another way to handle garbage
collecting your session if you are stuck with a FAT filesystem or any
other filesystem where atime tracking is not available.
Since PHP 4.2.3 it has used mtime (modified date) instead of atime. So, you
won't have problems with filesystems where atime tracking is not available.

session.referer_check contains the
substring you want to check each HTTP Referer for. If the
Referer was sent by the client and the substring was not
found, the embedded session id will be marked as invalid.
Defaults to the empty string.

session.entropy_file gives a path to an
external resource (file) which will be used as an additional
entropy source in the session id creation process. Examples are
/dev/random or /dev/urandom
which are available on many Unix systems.
This feature is supported on Windows since PHP 5.3.3. Setting
session.entropy_length to a non zero value
will make PHP use the Windows Random API as entropy source.

Note:
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.use_strict_mode specifies whether the
module will use strict session id mode. If this mode is enabled,
the module does not accept uninitialized session ID. If uninitialized
session ID is sent from browser, new session ID is sent to browser.
Applications are protected from session fixation via session adoption
with strict mode.
Defaults to 0 (disabled).

session.use_only_cookies specifies whether
the module will only use
cookies to store the session id on the client side.
Enabling this setting prevents attacks involved passing session
ids in URLs. This setting was added in PHP 4.3.0.
Defaults to 1 (enabled) since PHP 5.3.0.

Marks the cookie as accessible only through the HTTP protocol. This means
that the cookie won't be accessible by scripting languages, such as
JavaScript. This setting can effectively help to reduce identity theft
through XSS attacks (although it is not supported by all browsers).

session.cache_limiter specifies the cache
control method used for session pages.
It may be one of the following values:
nocache, private,
private_no_expire, or public.
Defaults to nocache. See also the
session_cache_limiter() documentation for
information about what these values mean.

session.use_trans_sid whether transparent
sid support is enabled or not. Defaults to
0 (disabled).

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.

PHP versions 4.2.3 and lower have an undocumented feature/bug that
allows you to initialize a session variable in the global scope,
albeit register_globals
is disabled. PHP 4.3.0 and later will warn you, if this feature is
used, and if
session.bug_compat_warn is also enabled. This feature/bug can be
disabled by disabling this directive.

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.

session.hash_bits_per_character allows you to define
how many bits are stored in each character when converting the binary
hash data to something readable. The possible values are '4' (0-9, a-f),
'5' (0-9, a-v), and '6' (0-9, a-z, A-Z, "-", ",").

A prefix used for the upload progress key in the $_SESSION.
This key will be concatenated with the value of
$_POST[ini_get("session.upload_progress.name")] to
provide a unique index.
Defaults to "upload_progress_".

The name of the key to be used in $_SESSION storing
the progress information. See also
session.upload_progress.prefix.
If $_POST[ini_get("session.upload_progress.name")]
is not passed or available, upload progressing will not be recorded.
Defaults to "PHP_SESSION_UPLOAD_PROGRESS".

Defines how often the upload progress information should be updated.
This can be defined in bytes (i.e. "update progress information after every 100 bytes"), or in percentages (i.e. "update progress information after receiving every 1% of the whole filesize").
Defaults to "1%".

The minimum delay between updates, in seconds.
Defaults to "1" (one second).

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 mor details on this functionality.

User Contributed Notes 12 notes

On debian (based) systems, changing session.gc_maxlifetime at runtime has no real effect. Debian disables PHP's own garbage collector by setting session.gc_probability=0. Instead it has a cronjob running every 30 minutes (see /etc/cron.d/php5) that cleans up old sessions. This cronjob basically looks into your php.ini and uses the value of session.gc_maxlifetime there to decide which sessions to clean (see /usr/lib/php5/maxlifetime).

You can adjust the global value in your php.ini (usually /etc/php5/apache2/php.ini). Or you can change the session.save_path so debian's cronjob will not clean up your sessions anymore. Then you need to either do your own garbage collection with your own cronjob or enable PHP's garbage collection (php then needs sufficient privileges on the save_path).

Why does Debian not use PHP's garbarage collection?For security reasons, they store session data in a place (/var/lib/php5) with very stringent permissions. With the sticky bit set, only root is allowed to rename or delete files there, so PHP itself cannot clean up old session data. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=267720 .

We found a session.save_path depth of 3 led to excessive wastage of inodes and in fact disk space in storing the directory tree. dir_indexes option on ext2/3/4 makes larger directories more feasible anyway, so we decided to move to a depth of 2 instead.

It took a little puzzling to figure out how to move the existing PHP sessions up one directory tree, but we ended up running this in the root sessions directory:

After having many problems with garbage collection not clearing my sessions I have resolved it through the following.

First I found this in the php.ini (not something i noticed as i use phpinfo(); to see my hosting ini).

; NOTE: If you are using the subdirectory option for storing session files; (see session.save_path above), then garbage collection does *not*; happen automatically. You will need to do your own garbage

; collection through a shell script, cron entry, or some other method. ; For example, the following script would is the equivalent of; setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes):; cd /path/to/sessions; find -cmin +24 | xargs rm

With this is mind there are options.

1. dont use a custom save_path.** This means if your isp hasnt defaulted your session temp to something safer than install default or you are using a shared directory for session data then you would be wise to use named sessions to keep your session from being viewable in other people's scripts. Creating a unique_id name for this is the common method. **

Being unable to find an actual copy of mod_files.sh, and seeing lots of complaints/bug fix requests for it, here's one that works. It gets all its parameters from PHP.INI, so you don't have the opportunity to mess up:

#!/bin/bash## Creates directories for PHP session storage.# Replaces the one that "comes with" PHP, which (a) doesn't always come with it# and (b) doesn't work so great.## This version takes no parameters, and uses the values in PHP.INI (if it# can find it).## Works in OS-X and CentOS (and probably all other) Linux.## Feb '13 by Jeff Levene.

[[ $# -gt 0 ]] && echo "$0 requires NO command-line parameters.It gets does whatever is called for in the PHP.INI file (if it can find it)." && exit 1

# Outputs the given (as $1) parameter from the PHP.INI file:# The "empty" brackets have a SPACE and a TAB in them.#PhpConfigParam() { [[ ! "$phpIni" ]] && return # Get the line from the INI file: varLine=`grep "^[ ]*$1[ ]*=" "$phpIni"`

This is how I set my session.save_pathsession.save_path = "1;/home/askapache/tmp/s" So to create the folder structure you can use this compatible shell script, if you want to create with 777 permissions change the umask to 0000;sh -o braceexpand -c "umask 0077;mkdir -p s/{0..9}/{a..z} s/{a..z}/{0..9}"

Then you can create a cronjob to clean the session folder by adding this to your crontab which deletes any session files older than an hour:@daily find /home/askapache/tmp/s -type f -mmin +60 -exec rm -f {} \; &>/dev/null

That will create sessions in folder like: /home/askapache/tmp/s/b/sess_b1aba5q6io4lv01bpc6t52h0ift227j6

I don't think any non-mega site will need to go more than 1 levels deep. Otherwise you create so many directories that it slows the performance gained by this.

To get session IDs to show up in URIs, and not get stored via cookies, you must not only set session.use_cookies to 0, but also set session.use_trans_sid to 1. Otherwise, the session ID goes neither in a cookie nor in URIs!