I came across with a strange problem today. I swept all the questions here but none of them resolved my issue.
When I start a session with session_start()
, a session file with format sess_xxxxxxxx
is created but the session variables is not written in the file.
To make sure I did some tests, couldn't find any problem. 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 />
";
}
prints
file_exists: true
is_dir: false
is_readable: true
is_writeable: true
so I see no problem of file permissions. However, if I run a very simple script as follows
<?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 settings related to session 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 will be appreciated much. Thanks