setting max_input_vars PHP.ini directive using ini_set - php

Can I set the max_input_vars PHP.ini directive in my code? I have it set at the default 1000, however I have a script that has many checkboxes and text fields that could, and quite possibly will, go over the 1000 limit.
I'm using PHP 5.3.10 and i'm not getting any errors doing this. Also, I can't find any documentation that states I can't do this.
ini_set('max_input_vars', 3000);
Thanks.

max_input_vars has a changeable mode of PHP_INI_PERDIR meaning it can't be changed using ini_set (only in php.ini, .htaccess or httpd.conf)

I know many people avoid accessing php.ini due to one reason or the other. so another way would be to create a .htaccess file in the operation folder and add the following codes and set the values to a higher value. Just add them directly no need to initialize anything in the .htaccess file
php_value max_input_vars 3000
php_value suhosin.get.max_vars 3000
php_value suhosin.post.max_vars 3000
php_value suhosin.request.max_vars 3000
This solution worked for me without accessing the php.ini file. since some of the web host providers give us a hard time when we want to access the php.ini file

Related

php specific function / url / file max post size?

I was wondering if you can set the post_max_size only for a specific page or function (in the php.ini)?
You can set it in the .htaccess
php_value upload_max_filesize 4M
php_value post_max_size 4M
but it doesn't work for a specific page. Also the ini_set() doesn't work for a specific page.
Any suggestions?
Not possible, unfortunately. post_max_size (and upload_max_filesize) are used before your script is started, so the only way to set them is in .htaccess or php.ini.
upload_max_filesize cannot be changed at runtime (using ini_set).
upload_max_filesize could not be set using ini_set(). The "official" list states that it is PHP_INI_PERDIR
You cannot change the upload_max_filesize at runtime. If you want custom limits for different parts of your app/website you have to set the upload_max_filesize & post_max_size to the maximum value that you want to allow, and after that you have to manually force lower limits with function filesize()
for example: you set upload_max_filesize & post_max_size at 100M, and you can manually reject an upload larger that 50M at a specific page/function by checking the size of the file
There are 3 places you can set it:
php.ini for globally on all pages
.htaccess and php script for local website/ instance.
try removing your .htaccess and see if it reads from the php.ini.
Just remember to also restart your server after changing the php.ini for it to take effect. if using linux, try:
sudo apachectl graceful
If that doesn't work, you will need to check your php code for the max size.
if its in the code, its too broad for me to say what it is.

php upload settings in a portable web application

I'm building a web app dealing with online file storage/access. In my local environment I used .htaccess to set
php_value upload_max_filesize 100M
php_value post_max_size 101M
After testing the app on a variety of servers I found that not all setups allow you to use the .htaccess method of modifying the ini settings. The solution I'm thinking of is to check for that permission during the install script and depending on what is allowed use either .htaccess, user directory php.ini, or ini_set(); for that particular installation.
ini_set() apparently doesn't work for post_max_upload. For some reason even though my php.ini has
user_ini.filename = ".user.ini"
it won't read the 2 directives in that file. Neither will it read the same information in the application directory named php.ini
And the .htaccess directives stated above result in a 500 Sever Misconfiguration Error. There's has to be a way to change the post_max_upload and upload_max_filesize on the fly.
The problem is that i don't know how to check for what is and isn't allowed on a particular server. Can someone help with that?
Your max execution time may be cutting the upload process short..
This is what I use in my admin area .htaccess -- maybe you can try these settings.
Don't use these settings globally, only set them for the .htaccess that has your upload or admin scripts isolated from the rest of your site, or else you might encounter problems with such a high amount of execution time.
php_value upload_max_filesize 30M
php_value post_max_size 30M
php_value max_execution_time 600
php_value max_input_time 200
If you can't get anything working perhaps your host has disabled .htaccess and ini setting changes...
One possible issue here is that I was trying to add the 2 lines in the original post to a php.ini file by themselves. Perhaps this is basic for some, but apparently you can't do that? It seems that you need to redeclare all of the rest of the php.ini settings into a directory-specific php.ini, and then just change the applicable lines.
This seems kind of a funky way to do things, though, so maybe I'm wrong... Can anyone tell me with more confidence that indeed this is the case, or that I'm mistaken?

PHP ini file and session deletion

Posted a question about an error I was getting the over day about Memory exceed when handling an image resize.
Managed to solve the problem with a local php.ini file and setting
[PHP]
upload_max_filesize = 5M
post_max_size = 5M
memory_limit = 64M
Now I realised I have a whole new problem :)
If I access a php file in the directoy with my custom local php.ini, it will override the original and
remove all my $_SESSION's
If I remove the local php.ini, it doesnt remove my sessions but then the image resize gives me a memory limit exceed error.
Any ideas? Can i set a php.ini (local) to just override the 3 parameters I want?
Thanks in advance,
P.s. tried setting it through CPANEL on tweak php.ini but those values seemed to be ignored.
Result
Had to contact tech support and they had to manually update my ini files.
If you have full control over your server, on most linux distros there is a conf.d directory which is loaded after all of the default php configuration, so you can override things. On ubuntu for example, that is /etc/php5/conf.d/, there you can create a file 'my.ini' (name doesn't matter as long as it ends in .ini) which will be automatically included.
If you don't have access to the entire server, there are several ways of altering those without overwriting everything:
Add the php configuration to .htaccess (if using Apache)
Set those options using ini_set('option', 'value'); in your php script
If you're going for the .htaccess route, here is an example, just append to end of your .htaccess file:
php_value upload_max_filesize 5M
php_value post_max_size 5M
php_value memory_limit 64M

How to the change php settings from php code?

I want to change the php setting but from ".php" page not php.ini. The settings I want to change is
upload_max_filesize, post_max_size and memory_limit
You can try it with a .htaccess file, if you have AllowOverride Options:
Place a file named .htaccess to your webroot:
php_value upload_max_filesize 10000
php_value post_max_size 10000
php_value memory_limit 10000
The only one of those that can be changed from within PHP is the last one, which can be changed with ini_set like this:
ini_set('memory_limit', '32M');
PHP always processes the client request before the PHP script is started. This means that uploaded files are already uploaded and posted forms are already fully posted beforeb he script starts. The upload and post settings can therefore not be set in the script, ebcause they are already irrelevant when the PHP script is started.
If your server administrator hasn't prevented it, you can use ini_set() to change the memory limit:
ini_set("memory_limit","16000000"); // abbreviations like "16M" work only
// in php.ini, always use full numbers here
The two other options are needed before the PHP script is loaded, there is no way to change those in php.ini.
Use
ini_set ('key', 'value');
Note that not all the available options can be changed using ini_set(). Here'is a list: ini.list
Read more in ini_set reference;

How to change php setting from php file? [duplicate]

I want to change the php setting but from ".php" page not php.ini. The settings I want to change is
upload_max_filesize, post_max_size and memory_limit
You can try it with a .htaccess file, if you have AllowOverride Options:
Place a file named .htaccess to your webroot:
php_value upload_max_filesize 10000
php_value post_max_size 10000
php_value memory_limit 10000
The only one of those that can be changed from within PHP is the last one, which can be changed with ini_set like this:
ini_set('memory_limit', '32M');
PHP always processes the client request before the PHP script is started. This means that uploaded files are already uploaded and posted forms are already fully posted beforeb he script starts. The upload and post settings can therefore not be set in the script, ebcause they are already irrelevant when the PHP script is started.
If your server administrator hasn't prevented it, you can use ini_set() to change the memory limit:
ini_set("memory_limit","16000000"); // abbreviations like "16M" work only
// in php.ini, always use full numbers here
The two other options are needed before the PHP script is loaded, there is no way to change those in php.ini.
Use
ini_set ('key', 'value');
Note that not all the available options can be changed using ini_set(). Here'is a list: ini.list
Read more in ini_set reference;

Categories