(PHP 4, PHP 5)

session_save_pathGet and/or set the current session save path


string session_save_path ([ string $path ] )

session_save_path() returns the path of the current directory used to save session data.

Список параметров


Session data path. If specified, the path to which data is saved will be changed. session_save_path() needs to be called before session_start() for that purpose.


On some operating systems, you may want to specify a path on a filesystem that handles lots of small files efficiently. For example, on Linux, reiserfs may provide better performance than ext2fs.

Возвращаемые значения

Returns the path of the current directory used for data storage.

Смотрите также


Session on clustered web servers !

We had problem in PHP session handling with 2 web server cluster. Problem was one servers session data was not available in other server.

So I made a simple configuration in both server php.ini file. Changed session.save_path default value to shared folder on both servers (/mnt/session/).

It works for me. :)
2008-02-06 01:25:07
Debian does not use the default garbage collector for sessions. Instead, it sets session.gc_probability to zero and it runs a cron job to clean up old session data in the default directory.

As a result, if your site sets a custom location with session_save_path() you also need to set a value for session.gc_probability, e.g.:


Otherwise, old files in '/home/' will never get removed!
2010-05-26 06:42:32
I made a folder next to the public html folder and placed these lines at the very first point in index.php

Location of session folder:


location of index.php


What I placed in index.php at line 0:

('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));

This is the only solution that worked for meHope this helps someone.
2013-10-03 10:45:28
If session.save_handler is set to files, on systems that have maximum path length limitations, when the session data file's path is too long, php may get you an error like "No such file or directory" and fails to start session, although the session-saving folder really exists on the disk.

You should:

1. Keep the session-saving folder's absolute path not too long
2. If you're with PHP 7.1+, don't set session.sid_length to a number too great, such as 255

I once got stuck with this problem on Windows and wasted hours to solve it.
2017-12-15 21:42:15
('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/tmp'));


(for using above code create a tmp folder/directory in your directory)
2019-02-09 17:29:34

    Поддержать сайт на родительском проекте КГБ