PHP session handling errors

后端 未结 13 1112
感动是毒
感动是毒 2020-12-15 17:33

I have this at the very top of my send.php file:

ob_start();
@session_start();

//some display stuff

$_SESSION[\'id\'] = $id; //$id has a value         


        
相关标签:
13条回答
  • 2020-12-15 18:00

    please make sure the session.save_path is set correctly in the php.ini. php needs read/write access to the directory to which this variable is set.

    more information: http://www.php.net/manual/en/session.configuration.php#ini.session.save-path

    0 讨论(0)
  • 2020-12-15 18:01

    you have to change your session.save_path setting to the accessible dir, /tmp/ for example

    How to change: http://php.net/session_save_path

    Being on the shared host, it is advised to set your session save path inside of your home directory but below document root

    also note that

    • using ob_start is unnecessary here,
    • and I am sure you put @ operator by accident and already going to remove it forever, don't you?
    0 讨论(0)
  • 2020-12-15 18:03

    When using the header function, php does not trigger a close on the current session. You must use session_write_close to close the session and remove the file lock from the session file.

    ob_start();
    @session_start();
    
    //some display stuff
    
    $_SESSION['id'] = $id; //$id has a value
    session_write_close();
    header('location: test.php');
    
    0 讨论(0)
  • 2020-12-15 18:06

    If you use a configured vhost and find the same error then you can override the default setting of php_value session.save_path under your <VirtualHost *:80>

    #
    # Apache specific PHP configuration options
    # those can be override in each configured vhost
    #
    php_value session.save_handler "files"
    php_value session.save_path    "/var/lib/php/5.6/session"
    php_value soap.wsdl_cache_dir  "/var/lib/php/5.6/wsdlcache"
    

    Change the path to your own '/tmp' with chmod 777.

    0 讨论(0)
  • 2020-12-15 18:07

    I got these two error messages, along with two others, and fiddled around for a while before discovering that all I needed to do was restart XAMPP! I hope this helps save someone else from the same wasted time!

    Warning: session_start(): open(/var/folders/zw/hdfw48qd25xcch5sz9dd3w600000gn/T/sess_f8bgs41qn3fk6d95s0pfps60n4, O_RDWR) failed: Permission denied (13) in /Applications/XAMPP/xamppfiles/htdocs/foo/bar.php on line 3
    
    Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Applications/XAMPP/xamppfiles/htdocs/foo/bar.php:3) in /Applications/XAMPP/xamppfiles/htdocs/foo/bar.php on line 3
    
    Warning: Unknown: open(/var/lib/php/session/sess_isu2r2bqudeosqvpoo8a67oj02, O_RDWR) failed: Permission denied (13) 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 (/var/lib/php/session) in Unknown on line 0
    
    0 讨论(0)
  • 2020-12-15 18:09

    I'm using php-5.4.45 and I got the same problem.

    If you are a php-fpm user, try edit php-fpm.conf and change listen.owner and listen.group to the right one. My nginx user is apache, so here I change these to params to apache, then it works well for me.

    For apache user, I guess you should edit your fast-cgi params refer the two params I mention above.

    0 讨论(0)
提交回复
热议问题