PHP Doku:: Liefert und/oder setzt den aktuellen Speicherpfad der Session - function.session-save-path.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSession-ErweiterungenSessionbehandlungSession-Funktionensession_save_path

Ein Service von Reinhard Neidl - Webprogrammierung.

Session-Funktionen

<<session_register

session_set_cookie_params>>

session_save_path

(PHP 4, PHP 5)

session_save_pathLiefert und/oder setzt den aktuellen Speicherpfad der Session

Beschreibung

string session_save_path ([ string $path ] )

session_save_path() gibt den Pfad des aktuellen Verzeichnisses zurück, das zum Speichern der Session-Daten verwendet wird.

Parameter-Liste

path

Der Pfad der Session-Daten. Sofern angegeben, wird der Pfad, unter dem Daten gespeichert werden, entsprechend geändert. Zu diesem Zweck muss session_save_path() vor session_start() aufgerufen werden.

Hinweis:

Unter manchen Betriebssystemen, wollen Sie vielleicht einen Pfad auf einem Dateisystem angeben, das sehr viele kleine Dateien effizient behandelt. Unter Linux, zum Beispiel, bietet reiserfs eventuell eine bessere Performance als ext2fs.

Rückgabewerte

Gibt den Pfad des aktuellen Verzeichnisses zurück, das zum Speichern der Session-Daten verwendet wird.

Siehe auch


9 BenutzerBeiträge:
- Beiträge aktualisieren...
branislav dot ristic at gmail dot com
1.06.2010 12:28
After a lot of searches, tests and pain, the only one that worked for me was this:

session_save_path(realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));
alvaro at demogracia dot com
26.05.2010 12:42
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.:

<?php
session_save_path
('/home/example.com/sessions');
ini_set('session.gc_probability', 1);
?>

Otherwise, old files in '/home/example.com/sessions' will never get removed!
Matthias H. (DE)
14.03.2010 12:40
Under PHP for Windows, you can improve the speed, when you store all session-files on ramdisk. A freeware-ramdisk you can download by http://www.techsnack.net/gavotte-ramdisk-free-virtual-hardisk .

A other alternativ is store you session-datas to apc-user-cache (see php-apc-extension).
TK
23.02.2010 2:29
After a search for the cause of a issue causing users to have to login twice, I've found a call to session_save_path() was the culprit.

What was happening was: the session save path was set, a session was opened, some variables were set and the session was closed.  This was resulting in an empty file in the specified session save path and of course no session data on the next page load.  Oddly, on the second attempt the data was saved as expected.

I found that removing the call to session_save_path() resolved the issue.  My final solution was to replace the call to session_save_path($path) with an equivalent call to ini_set('session.save_path', $path).
sampathperera at hotmail dot com - Sri Lanka
6.02.2008 8:25
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. :)
gt at psgam dot de
25.02.2005 14:58
Note that you shouldn't use session_save_path() directly for performing file operations.
It returns the configuration option, not the directory.
As stated in /manual/en/ref.session.php#ini.session.save-path there can be a numeric argument separated with a semicolon in front of the "real" path.
I used the following code to get rid of it:
<?php
$sessionpath
= session_save_path();
if (
strpos ($sessionpath, ";") !== FALSE)
 
$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
?>
Doesn't allow ; to appear in the directory names, but hey.

Regards,
Gero
designofgod at yahoo dot com
15.02.2005 3:12
sometime you need to change session.save_path because server system distributed more then one machine and you can not reach php.ini file example sourceforge.net. Then you can do that with .htaccess file which is kind of configuration file for Apache under one directory. anyway I added

php_value session.save_path /home/groups/f/f4/f4l/tmp/

now my sessions work very well I hope :)
webmaster at gardenchemicals dot co dot uk
16.09.2004 16:59
This is an absolute must if you have an important login on a shared server. Without it, other users of the server can do the following to bypass login:

* Visit login page, browse through cookies and grab the session id.
* Create a PHP script on their account that grabs and sets session variables for a given session id.
* Read and change any values for that session id (for example passwords or session keys), and therefore gain access to the protected area.

All users on web hosting should choose an dir below the HTTP directory struct, but within their user area to store the session files.
a9504778 at unet dot univie dot ac dot at
15.01.2001 0:09
dont forget: if you use session_save_path on the page, that registers a variable, you have also to use session_save_path on all the pages, where you access the session-variable. under win32 you can use the double \\ to specify eg "c:\\temp\\"



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)