PHP open_basedir的一些問題
open_basedir: 將用戶可操作的文件限製在某目錄下(xià);
——————————————————————————–
如下是php.ini中的原文(wén)說明以及默認配置:
; 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可將用戶訪問文件的活(huó)動(dòng)範圍限製在指定的區域,通常是其家目(mù)錄的路徑,也可(kě)用符號”.”來代(dài)表當前目錄。注意用open_basedir指定的限製實際上是(shì)前綴,而(ér)不是目(mù)錄名(míng)。舉例來(lái)說: 若”open_basedir = /dir/user”, 那麽目錄(lù) “/dir/user” 和 “/dir/user1″都(dōu)是可以訪問的。所以如果(guǒ)要將訪問限製在僅為(wéi)指定的目錄,請用斜線結束路(lù)徑名。例如設置成:“open_basedir = /dir/user/”
open_basedir也可以同時設置多個目錄, 在Windows中用分號分隔目錄(lù),在任何其它係統中用冒號分隔目錄。當其作用於Apache模塊(kuài)時,父目錄中的open_basedir路徑(jìng)自動被繼(jì)承。
有三種方法可以在Apache中為指定的用戶做獨立的設置:
(a) 在Apache的httpd.conf中Directory的(de)相應設(shè)置方法:
php_admin_value open_basedir /usr/local/apache/htdocs/
#設置多個目錄可以參考如下(xià):
php_admin_value open_basedir /usr/local/apache/htdocs/:/tmp/
(b) 在Apache的httpd.conf中VirtualHost的相應設(shè)置方(fāng)法:
php_admin_value open_basedir /usr/local/apache/htdocs/
#設置多個目錄可以參考如下:
php_admin_value open_basedir /var/www/html/:/var/tmp/
(c) 因為VirtualHost中設(shè)置了open_basedir之後, 這個(gè)虛擬用戶就不會再自動繼承php.ini中(zhōng)的open_basedir設(shè)置值(zhí)了,這就難以達到靈活的配置措施, 所以(yǐ)建議您不要在(zài)VirtualHost中設置此項限製. 例如,可以在php.ini中設置open_basedir = .:/tmp/, 這個(gè)設置表示允許訪問當前目錄(即PHP腳本文件所在之目錄)和/tmp/目錄(lù).
請注意: 若在php.ini所設置的上傳文件臨時目錄為/tmp/, 那麽設置open_basedir時就必須包含/tmp/,否則會導(dǎo)致上傳失(shī)敗. 新(xīn)版(bǎn)php則會提示”open_basedir restriction in effect”
警告信息, 但move_uploaded_file()函數仍然可以成功取出/tmp/目錄下的上(shàng)傳文件,不知道這是漏洞還是新功能.
關鍵詞:PHP,open_basedir
閱(yuè)讀(dú)本文後您有什麽感想(xiǎng)? 已有 人給出評價!
- 1
- 1
- 1
- 1
- 1
- 1