0

I am building a Modules for SUgarCRM that is in PHP.

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.

So I need to have code that:

  1. Reads the PHP INI setting for max_input_vars this part is easy. If it is lower than say 3000 I need to increase it in the .htaccess file
  2. Read in the contents of the .htaccess file
  3. Add this value to the htacess php_value max_input_vars 3000
  4. Save the .htaccess file with all the old contents as well as the new setting

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?

1
  • Whether or not this is possible will depend on how the sysadmin has setup the server you're running on. Sometimes it will work, sometimes it won't. Also on some servers, you cannot set php_value from a htaccess file — putting that line of code in the htaccess will sometimes bring the entire server offline until somebody edits the htaccess file to remove it. Commented Oct 15, 2014 at 1:50

1 Answer 1

3

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). Sorry if that's unhelpful. :-\

Sign up to request clarification or add additional context in comments.

7 Comments

I've seen someone get the contents of the current htaccess file, store as string, delete the .htaccess file and then create another one with the previous data + the new data they wanted appended to it. (Last resort though, could be issue-filled)
@Darren: Deleting the file would require write access to the directory containing the file, which wouldn't really be much better.
Exactly why i said Last resort though, could be issue-filled :)
Thanks for the code sample. I'm really hoping permissions allow it, the worst part is it will be installed to many different peoples servers so i'm bound to have issues im sure!
My module has a PHP file/script that is ran when the module is installed, well directly after installation where I can put code like this. IT is generally used for creating custom Database tables and things like that so I will try to use this code there as well. I think I need to somehow check and see if the file is writable before running this though, do you know what I could use to check that the file is editable first?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.