简体   繁体   中英

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(); in my index.php at line 4. How can I fix this?

Your /tmp/ folder isn't writable. Make it writable.

chmod u+w /tmp/

You can test it with 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

It looks like /tmp is on a read-only file system. This is not normal. Tell your sysadmin/hosting provider to have a look at it; 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 ).

Yuo can't write on /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. Take a look: php manual

This was a known bug in version(s) of PHP . Depending on your server environment, you can try setting the sessions folder to 777:

/var/lib/php/session (your location may vary)

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).

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:

<?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(); 
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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