PHP does not populate session files
I got a weird problem today. I covered all the questions, but none of them solved my problem.
When I start a session with session_start()
, a formatted session file is created sess_xxxxxxxx
, but the session variables are not written to the file.
To make sure I did some tests, I couldn't find any issues. For example the following code
<?php
$path = '/var/lib/php5/sess_aq2ctf49sa0jtplbaqqanqogt3';
foreach( array('file_exists', 'is_dir', 'is_readable', 'is_writeable') as $fn ) {
$rc = $fn($path);
echo $fn, ': ', $rc ? 'true' : 'false', "<br />\n";
}
prints
file_exists: true
is_dir: false
is_readable: true
is_writeable: true
so I don't see file permissions issues. However, if I run a very simple script like this
<?php
session_start();
$_SESSION['test'] = "Session test";
echo $_SESSION['test'];
?>
I only get empty session files
drwx-wx-wt 2 www-data www-data 40K Dec 9 04:27 .
drwxr-xr-x 38 root root 4.0K Dec 8 05:09 ..
-rw------- 1 www-data www-data 0 Dec 9 04:28 sess_4cfr69tfe3euujr70p4vuj95v7
-rw------- 1 www-data www-data 0 Dec 9 04:23 sess_aq2ctf49sa0jtplbaqqanqogt3
-rw------- 1 www-data www-data 0 Dec 9 04:27 sess_bk89n2qomkp0cmm0r901i4dqm5
-rw------- 1 www-data www-data 0 Dec 9 04:26 sess_h4vsd0nn7mpbbl539f590f0n16
-rw------- 1 www-data www-data 0 Dec 9 04:26 sess_na6cgdimp4t3sk1pu86rcu4e75
You can see all session related settings in php.ini below
session.save_handler = files
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 0
session.gc_divisor = 1000
session.gc_maxlifetime = 86400
session.bug_compat_42 = Off
session.bug_compat_warn = Off
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
Any help would be greatly appreciated. Thanks to
+3
source to share