简体   繁体   English

可以用PHP修改htaccess文件吗?

[英]Possible to modify htaccess file with PHP?

I am building a Modules for SUgarCRM that is in PHP. 我正在用PHP构建SUgarCRM的模块。

When a user installs the module, I have access to a script that can be run as part of the install process... 当用户安装模块时,我可以访问可以在安装过程中运行的脚本...

I basically need to modify the .htaccess file and increase the max_input_vars INI setting. 我基本上需要修改.htaccess文件并增加max_input_vars INI设置。

So I need to have code that: 因此,我需要具有以下代码:

  1. Reads the PHP INI setting for max_input_vars this part is easy. 读取max_input_vars的PHP INI设置,这一部分很容易。 If it is lower than say 3000 I need to increase it in the .htaccess file 如果它低于3000,我需要在.htaccess文件中增加它
  2. Read in the contents of the .htaccess file 读入.htaccess文件的内容
  3. Add this value to the htacess php_value max_input_vars 3000 将此值添加到htacess php_value max_input_vars 3000
  4. Save the .htaccess file with all the old contents as well as the new setting 保存.htaccess文件以及所有旧内容和新设置

Is this even practical? 这甚至可行吗? I think I have seen WordPress do such an action before and I will look there for help/ideas too but I could use any help in this? 我想我以前曾经看过WordPress做过这样的操作,我也会在那儿寻求帮助/想法,但是我可以在这方面使用任何帮助吗?

As long as the file has writable permissions by the user that is running the script, then you should be able to use: 只要文件具有运行脚本的用户的可写权限,您就可以使用:

file_put_contents('path/to/.htaccess', "\nphp_value max_input_vars 3000", FILE_APPEND);

If permissions are an issue, and you don't want to make the .htaccess file writable by whatever user is running the script, then I know there are ways to escalate your current permissions (by changing the current user), using something like a C++ executable, but I don't know the details (I've seen it done by a guy I work with). 如果权限是一个问题,并且您不希望任何正在运行脚本的用户都可以使.htaccess文件可写,那么我知道可以使用一些类似的方法来升级您的当前权限(通过更改当前用户)。 C ++可执行文件,但我不知道细节(我见过一个与我合作的人来完成)。 Sorry if that's unhelpful. 抱歉,这无济于事。 :-\\ :-\\

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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