首頁  >  文章  >  後端開發  >  PHP 設定檔中open_basedir選項作用

PHP 設定檔中open_basedir選項作用

高洛峰
高洛峰原創
2017-01-06 14:51:561742瀏覽

如下是php.ini中的原文說明以及預設設定: 
; open_basedir, if set, limits all file operations to the defined directory 
; and below. This directive makes most sense if
; and below. This directive makes most sense if
; and below. This directive makes most sense if if. -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目錄的路徑,也 
可用符號"."來代表目前目錄。注意用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_valueue #設定多個目錄可以參考如下: 
php_admin_value open_basedir /usr/local/apache/htdocs/:/tmp/ 


(b) 在Apache的httpd.conf 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;../syssiteite ;../templates;../language;../../language;../../../language;../../../../language"

更多PHP 配置文件中open_basedir選項作用相關文章請關注PHP中文網! 🎜
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn