简体   繁体   English

奇怪的PHP会话错误

[英]strange php session error

I get a session error which I did not have before which is strange. 我收到一个之前没有的会话错误,这很奇怪。

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`

I have only session_start(); 我只有session_start(); in my index.php at line 4. How can I fix this? 在第4行的index.php中。如何解决此问题?

Your /tmp/ folder isn't writable. 您的/tmp/文件夹不可写。 Make it writable. 使它可写。

chmod u+w /tmp/

You can test it with is_writable(session_save_path()) . 您可以使用is_writable(session_save_path())对其进行测试。

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 警告:session_start()[function.session-start]:打开(/ tmp / sess_6768c4a8b1cff40d24a3a87de701c865,O_RDWR)失败:/home/public_html/ctcms/index.php中第4行的只读文件系统 (30)

It looks like /tmp is on a read-only file system. 看起来/tmp在只读文件系统上。 This is not normal. 这是不正常的。 Tell your sysadmin/hosting provider to have a look at it; 告诉您的sysadmin / hosting提供商查看一下; the machine may have a serious problem. 机器可能有严重问题。

If the machine is yours, check the logs for any errors related to the file system and try to remount the disk in read-write ( mount -o remount,rw /dev/yourdevicehere ). 如果是您的计算机,请检查日志中是否存在与文件系统相关的任何错误,然后尝试以读写方式mount -o remount,rw /dev/yourdevicehere磁盘( mount -o remount,rw /dev/yourdevicehere )。

Yuo can't write on /tmp/ 您无法在/tmp/上写

Make it writable and redo the operation. 使它可写并重做该操作。

Moreover, remember that session_start() have to be the first operation that you do on the page. 此外,请记住session_start() 必须是您在页面上执行的第一项操作。 Take a look: php manual 看看: php手册

This was a known bug in version(s) of PHP . 这是PHP版本中的一个已知错误 Depending on your server environment, you can try setting the sessions folder to 777: 根据您的服务器环境,您可以尝试将session文件夹设置为777:

/var/lib/php/session (your location may vary) /var/lib/php/session (您的位置可能有所不同)

I ended up using this workaround: 我最终使用了这种解决方法:

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

You will have to create this folder and make it writeable. 您将必须创建此文件夹并使它可写。 I havent messed around with the permissions much, but 777 worked for me (obviously). 我没有弄乱权限,但是777为我工作(很明显)。

Make sure the place where you are storing your sessions isn't accessible to the world. 确保您的会话所在的地方不被全世界访问。

This solution may not work for everyone, but I hope it helps some people! 此解决方案可能不适用于每个人,但希望对某些人有所帮助!

please select an answer and mark accordingly. 请选择一个答案并做相应标记。

Before start session, check if the file of session is writable and, if not, delete the cookie: 在开始会话之前,请检查会话文件是否可写,如果不能,则删除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(); 
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM