4

Having an issue with number of form elements in a huge form. Some elements arent included in the post.

After some searching I saw this: $_POST max array size

$this->input->post('formelement') uses max_input_vars as limiter.

Answer from link above is ok. I understand that I have to use max_input_vars in php.ini. That's ok locally, but if my webhosting company for my production server doesn't allow me to change this settings on their server - this is not an option.

I'm using codeIgniter and creating a form like this:

<?php        
$attributes = array('id' => 'id of form');
echo form_open('controller/function-name', $attributes);
//actual form content
echo form_close();
?>

After some further reading I understand that I could use http://input for bypassing this max_input_var limit.

I could get the raw data output by doing this in controller/function-name

$postdata = file_get_contents("php://input"); 

But then I would have to do things manually checking csrf-values etc, populating postdata, exploding it correctly etc etc....

I've also tried this in htaccess: (based on max_input_vars limited in PHP 5.2.17)

RewriteEngine On
RewriteBase /
php_value max_input_vars 6000
php_value suhosin.post.max_vars 6000
php_value suhosin.request.max_vars 6000
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

but then webpage is not accesible and I'm getting an internal error.

The server I'm trying to make the change on is using PHP Version 5.5.7-1+sury.org~precise+1

Is it possible to change max_input_vars in runtime (or am I doing something wrong with htaccess?)

Community
  • 1
  • 1
bestprogrammerintheworld
  • 5,417
  • 7
  • 43
  • 72

1 Answers1

5

No, it's not possible to change it at runtime.

This is because at runtime the input has been already processed.

So the setting either resulted in an error already or it is too late to change it.

This is also documented in the manual as it lists places where you can change ini directives:

If you're unsure where all those places to change PHP configuration are and how to use them, there is another page in that section:

hakre
  • 193,403
  • 52
  • 435
  • 836
  • This answers the actual question. but what are my options. Am I doing something incorrectly with htaccess? – bestprogrammerintheworld May 25 '14 at 09:03
  • I get the error: Exceeded the max_input_var. please change in your php.ini (or something like that) – bestprogrammerintheworld May 25 '14 at 09:05
  • Well, as the error message suggests, change it in the php.ini. (sorry if that sounds like that I state the obvious) – hakre May 25 '14 at 09:06
  • Yes, I tried to make that clear in the question. Locally on my webserver (wamp) I could do that, but not on my webhosting server. – bestprogrammerintheworld May 25 '14 at 09:07
  • @bestprogrammerintheworld: You can do so as well with your webhosting server by contacting the support of your hoster and ask them for guidance and support. As you're concerned about a limit, it's either possible or prevented by the hoster. So it's either possible or not possible which pretty much resembles the runtime setting possibility in PHP. So in the end this might just be a limitation of PHP with your webhoster. Then the answer is to switch hosts. – hakre May 25 '14 at 09:08
  • Ok. Thanks! I've got my answer. I wanted another one (something like: just do execute('max_input_vars = 2000); ;-) , but at the same time I got a great answer. Thanks a lot! – bestprogrammerintheworld May 25 '14 at 09:18