duanlu0386 2014-12-09 09:35
浏览 37

PHP不会填写会话文件

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

  • 写回答

1条回答 默认 最新

  • dongxie5698 2014-12-09 10:42
    关注

    Try to make the directory the owner of your webserver.

    sudo chown www-data:www-data /var/lib/php5
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100