2013-03-01 96 views
3

为php.ini文件中的用户访问,因为我们在php.ini文件中有一些自定义的配置我们明显将其存储在我们的网站&的根目录,因此任何用户将能够看到它。拒绝用的.htaccess

我如何我可以阻止人们通过他们的浏览器,例如访问它?

回答

4

尝试把这个在您的.htaccess

<FilesMatch "php.ini"> 
    Order allow,deny 
    Deny from all 
</FilesMatch> 

它拒绝任何人访问试图达到php.ini

编辑:允许和顺序在Apache的2.4弃用。您应该改用Require all denied

<FilesMatch "php.ini"> 
    Require all denied 
</FilesMatch> 
+0

非常感谢! – Brett 2013-03-01 16:48:09

1

一种方式做到这一点是在php.ini文件的开始插入这样的事情:

/***************DO NOT ALLOW DIRECT ACCESS************************************/ 
if ((strpos(strtolower($_SERVER[ 'SCRIPT_NAME' ]), strtolower(basename(__FILE__)))) !== FALSE) { // TRUE if the script's file name is found in the URL 
    header('HTTP/1.0 403 Forbidden'); 
    die('<h2>Forbidden! Access to this page is forbidden.</h2>'); 
} 
/*****************************************************************************/ 
+1

您可以在'php.ini'中执行PHP代码吗? – 2013-03-19 15:55:41