简体   繁体   中英

Disable some php function on special directory

I want disable execute some php function like file_put_content , exec , eval on special directory.

I can use disable_functions in php.ini but how can define a special folder like c:\\poject\\public

You can't use the disable_functions setting anywhere other than in a php.ini file, according to the PHP documentation ,.

If you need per-vhost or per-directory restrictions on functions, I would suggest using separate instances of PHP-FPM , each of which can have its own php.ini. It also provides additional security benefits, such as complete sandboxing per daemon instance.

EDIT:

You can read about it on official documentation

or

php-fpm example configuration for both UNIX and TCP sockets.

If you have a working version of php.ini that disables the functions you want, then you just need to "link" the folder to that specidif .ini file. This means that your web server should, when serving files from that directory, should use that specific .ini file instead of the system one.

If you are using Apache2 as a server, a solution can be found here you can define a specific php.ini file for each virtualhost. Let's say you specific folder is /var/www/web1, you should put the php.ini with the function disabled into /var/www/web1 and use this Apache2 configuration

<VirtualHost 1.2.3.4:80>
[...]
PHPINIDir /var/www/web1
[...]
</VirtualHost>

If you are not familiar with or not using VirtualHosts (but still using Apache2), another possibile solution is putting PHP configuration into a file named .htaccess in the folder, with a syntax like this:

php_value disable_functions "file_put_content,exec,eval"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM