How can I fix the Permission error when I call ses

2019-01-03 18:47发布

when I uploaded the script to the server I got this error

Warning: Unknown: open(/tmp/sess_58f54ee6a828f04116c2ed97664497b2, 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 (/tmp) in Unknown on line 0

the error appeared when I call session_start(); although I set the permission of /tmp folder to 777 .

15条回答
一纸荒年 Trace。
2楼-- · 2019-01-03 19:20

Add following line

ini_set('session.save_path', getcwd() . '/tmp');

before

session_start(); 
查看更多
Luminary・发光体
3楼-- · 2019-01-03 19:23

I had this problem in the following situation:

  1. I filled some session vars with PHP
  2. While the session was still active, I changed from PHP 5.4 to 5.3 on my host.
  3. Reloading the page gave the error, described above.
  4. Reset the PHP version to 5.4 again.
  5. Used session_unset(); and session_destroy(); to clean the current session.
  6. Changed the PHP version back to 5.3.
  7. Now it works again.

Conclusion: For an irrelevant reason I had to change my PHP version, and while switching with sessions alive, the sessions get corrupted.

查看更多
做个烂人
4楼-- · 2019-01-03 19:23

If :

  • session.gc_probability > 0
  • session files are created by different user(s) (e.g. root and apache).
  • session files are all stored in the same place (e.g. /var/lib/php/session)

Then you'll see this error when e.g. the Apache PHP process attempts to run garbage collection on the session files.

Fixes :

  1. Reconfigure PHP so gc_probability is 0, and have a cron job removing the old/stale file(s).
  2. Have each different user save their session files in separate place(s) (session_save_path() etc).
查看更多
登录 后发表回答