chmod() has been disabled for security reasons

简介: 最近用 codeigniter 写一个小系统,引用了session 库,codeigniter默认的session存储方式为files。鉴于安全性,文件即肯定涉及到权限问题。在类 UNIX 操作系统中,这可以通过在该目录上执行 chmod 命令,将权限设置为 0700 来实现, 这样就可以只允许目录的所有者执行读取和写入操作。

最近用 codeigniter 写一个小系统,引用了session 库,codeigniter默认的session存储方式为files。鉴于安全性,文件即肯定涉及到权限问题。

在类 UNIX 操作系统中,这可以通过在该目录上执行 chmod 命令,将权限设置为 0700 来实现, 这样就可以只允许目录的所有者执行读取和写入操作。但是要注意的是,脚本的执行者通常不是你自己, 而是类似于 'www-data' 这样的用户,所以只设置权限可能会破坏你的程序。

但用户买的是万网的虚拟主机,默认是没有开启 chmod 函数的设置。于是就碰到了这个问题:"chmod() has been disabled for security reasons"。解决方法有两个:

1.开启设置

登录万网虚拟主机控制面板:点击左侧【高级环境设置】->【php.ini设置】,将【chmod函数】设置为开启。

2.更换session存储方式为数据库驱动

在config.php文件里设置

$config['sess_driver'] = 'database';
$config['sess_save_path'] = 'ci_sessions';

要求在数据库中建表:ci_sessions,如MySql:

CREATE TABLE IF NOT EXISTS `ci_sessions` (
    `id` varchar(40) NOT NULL,
    `ip_address` varchar(45) NOT NULL,
    `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
    `data` blob NOT NULL,
    KEY `ci_sessions_timestamp` (`timestamp`)
);

参考资料

http://codeigniter.org.cn/user_guide/libraries/sessions.html
https://help.aliyun.com/knowledge_detail/36434.html

相关文章
|
2月前
|
安全 PHP
解决pcntl_fork() has been disabled for security reasons in file /www/wwwroot/192.168.21.2/vendor/wor
解决pcntl_fork() has been disabled for security reasons in file /www/wwwroot/192.168.21.2/vendor/wor
53 0
解决pcntl_fork() has been disabled for security reasons in file /www/wwwroot/192.168.21.2/vendor/wor
|
Apache 数据安全/隐私保护
|
Linux 安全
SELinux: Could not downgrade policy file
在配置nfs服务器,设定selinux时,碰到了SELinux: Could not downgrade policy file的错误提示,下文是其解决方案。
1360 0