PHP 配置文件中open_basedir选项作用

2015-01-24信息快讯网

open_basedir: 将用户可操作的文件限制在某目录下

如下是php.ini中的原文说明以及默认配置:
; open_basedir, if set, limits all file operations to the defined directory
; and below. This directive makes most sense if used in a per-directory or
; per-virtualhost web server configuration file. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
open_basedir = .
open_basedir可将用户访问文件的活动范围限制在指定的区域,通常是其家目录的路径,也
可用符号"."来代表当前目录。注意用open_basedir指定的限制实际上是前缀,而不是目录名。
举例来说: 若"open_basedir = /dir/user", 那么目录 "/dir/user" 和 "/dir/user1"都是
可以访问的。所以如果要将访问限制在仅为指定的目录,请用斜线结束路径名。例如设置成:
"open_basedir = /dir/user/"

open_basedir也可以同时设置多个目录, 在Windows中用分号分隔目录,在任何其它系统中用
冒号分隔目录。当其作用于Apache模块时,父目录中的open_basedir路径自动被继承。

有三种方法可以在Apache中为指定的用户做独立的设置:

(a) 在Apache的httpd.conf中Directory的相应设置方法:

php_admin_value open_basedir /usr/local/apache/htdocs/
#设置多个目录可以参考如下:
php_admin_value open_basedir /usr/local/apache/htdocs/:/tmp/


(b) 在Apache的httpd.conf中VirtualHost的相应设置方法:
php_admin_value open_basedir /usr/local/apache/htdocs/
#设置多个目录可以参考如下:
php_admin_value open_basedir /var/www/html/:/var/tmp/

(c) 因为VirtualHost中设置了open_basedir之后, 这个虚拟用户就不会再自动继承php.ini
中的open_basedir设置值了,这就难以达到灵活的配置措施, 所以建议您不要在VirtualHost
中设置此项限制. 例如,可以在php.ini中设置open_basedir = .:/tmp/, 这个设置表示允许
访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录.

请注意: 若在php.ini所设置的上传文件临时目录为/tmp/, 那么设置open_basedir时就必须
包含/tmp/,否则会导致上传失败. 新版php则会提示"open_basedir restriction in effect"
警告信息, 但move_uploaded_file()函数仍然可以成功取出/tmp/目录下的上传文件,不知道
这是漏洞还是新功能.

针对ShopEx472版本的配置:

open_basedir = "D:/Server;../catalog;../include;../../home;../syssite;../templates;../language;../../language;../../../language;../../../../language"
8个出色的WordPress SEO插件收集
php提交表单时判断 if($_POST[submit])与 if(isset($_POST[submit])) 的区别
php5 apache 2.2 webservice 创建与配置(java)
PHP Session_Regenerate_ID函数双释放内存破坏漏洞
PHP中删除变量时unset()和null的区别分析
DEDE采集大师官方留后门的删除办法
从php核心代码分析require和include的区别
深入理解PHP之require/include顺序 推荐
php iconv() : Detected an illegal character in input string
Notice: Undefined index: page in E:\PHP\test.php on line 14
php运行出现Call to undefined function curl_init()的解决方法
php Notice: Undefined index 错误提示解决方法
《Head First 设计模式》代码之PHP版(面向对象学习)第1/2页
PHP is_dir() 判断给定文件名是否是一个目录
php echo()和print()、require()和include()函数区别说明
php is_file()和is_dir()用于遍历目录时用法注意事项
php遍历目录viewDir函数
PHP 配置open_basedir 让各虚拟站点独立运行
php download.php实现代码 跳转到下载文件(response.redirect)
php PDO中文乱码解决办法
PHP form 表单传参明细研究
php fckeditor 调用的函数
php ignore_user_abort与register_shutdown_function 使用方法
C# Assembly类访问程序集信息
php MsSql server时遇到的中文编码问题
php Undefined index的问题
php session 错误
php 无限级 SelectTree 类
PHP mkdir()定义和用法
php下HTTP Response中的Chunked编码实现方法
PHP syntax error, unexpected $end 错误的一种原因及解决
php include,include_once,require,require_once
用PHP读取RSS feed的代码
PHP下用rmdir实现删除目录的三种方法小结
require(),include(),require_once()和include_once()区别
PHP 中dirname(_file_)讲解
©2014-2024 dbsqp.com