php自定义session保存目录

PHP中文网
Release: 2016-06-24 12:22:55
Original
959 people have browsed it

今天一个客户网站突然报出一堆错误提示,提示代码如下:

Warning: session_start() [function.session-start]: open(/var/lib/php/session/sess_0dj5ol1fp235a0scu79s8c33t1, O_RDWR) failed: Permission denied (13) in /home/wethost/wwwroot/include/seccode.inc.php on line 7

Warning: Unknown: open(/var/lib/php/session/sess_0dj5ol1fp235a0scu79s8c33t1, 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

以上提示的大概意思是说没有读取SESSION目录中文件的权限。想必是虚拟主机提供方配置服务器做了某些修改导致的。为了免生麻烦,本次就直接在php中设置session的文件保存目录吧。

在php代码中加入如下代码,要加在 session_start() 的前面。

ini_set('session.save_path', dirname(__FILE__).'/Alixixi/');

或者:

session_save_path(dirname(__FILE__).'/Alixixi/');

以上即将网站生成的session文件保存到了网站当前根目录的Alixixi目录下面。

注意并不是所有配置参数都可以在脚本中设置,这个跟参数的作用域有关系。

以下内容为引用 PHP的配置参数作用域说明

PHP_INI_PERDIR:指令可以在php.ini、httpd.conf或.htaccess文件中修改;

PHP_INI_SYSTEM:指令可以在php.ini和httpd.conf中修改;

PHP_INI_USER:指令可以在用户脚本中修改;

PHP_INI_ALL:指令可以在任何地方修改;

所以只有PHP_INI_USER和PHP_INI_ALL作用域的参数才可以在脚本中的设置生效。至于参数的具体作用域可以在网络中检索。


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!