奇怪的PHP会话错误

时间:2012-03-06 07:49:17

标签: php

我收到一个会话错误,之前我没有这个错误很奇怪。

Warning: session_start() [function.session-start]: open(/tmp/sess_6768c4a8b1cff40d24a3a87de701c865, O_RDWR) failed: Read-only file system (30) in /home/public_html/ctcms/index.php on line 4

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/public_html/ctcms/index.php:4) in /home/public_html/ctcms/index.php on line 4

 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/public_html/ctcms/index.php:4) in /home/adrian/public_html/ctcms/index.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/ctcms/index.php:4) in /home/public_html/ctcms/library/CT/Controller.php on line 40

Warning: Unknown: open(/tmp/sess_6768c4a8b1cff40d24a3a87de701c865, O_RDWR) failed: Read-only file system (30) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0`

我在第4行的index.php中只有session_start();。我该如何解决这个问题?

5 个答案:

答案 0 :(得分:4)

您的/tmp/文件夹无法写入。让它可写。

chmod u+w /tmp/

您可以使用is_writable(session_save_path())进行测试。

答案 1 :(得分:2)

  

警告:session_start()[function.session-start]:open(/ tmp / sess_6768c4a8b1cff40d24a3a87de701c865,O_RDWR)失败:/ home / public_html / ctcms /中的只读文件系统(30)第4行的index.php

看起来/tmp位于只读文件系统上。 这不正常。告诉您的系统管理员/托管服务提供商查看它;机器可能有严重的问题。

如果计算机是您的,请检查日志中是否存在与文件系统相关的任何错误,并尝试以读写方式重新安装磁盘(mount -o remount,rw /dev/yourdevicehere)。

答案 2 :(得分:1)

Yuo无法写在/tmp/

使其可写并重做操作。

此外,请记住session_start()必须您在页面上执行的第一个操作。 看看:php manual

答案 3 :(得分:0)

这是PHP版本中的known bug。根据您的服务器环境,您可以尝试将sessions文件夹设置为777:

/var/lib/php/session(您的位置可能会有所不同)

我最终使用了这种解决方法:

session_save_path('/path/not/accessable_to_world/sessions');
ini_set('session.gc_probability', 1);

您必须创建此文件夹并使其可写。我没有多少搞乱权限,但777为我工作(显然)。

确保世界无法访问您存储会话的地方。

此解决方案可能并不适用于所有人,但我希望它可以帮助一些人!

请选择一个答案并进行相应的标记。

答案 4 :(得分:-1)

在开始会话之前,检查会话文件是否可写,如果没有,则删除cookie:

<?php
session_save_path("/tmp");
if (isset($_COOKIE[session_name()])) {
    if(!is_writable("/tmp/sess_".$_COOKIE[session_name()])) {
        setcookie(session_name(), '', time()-42000, '/');
        header("Location: ./");
    }
}
session_start(); 
?>