Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : PHP Options&Information : ini_set

ini_set

Sets the value of a configuration option (PHP 4, PHP 5)
string ini_set ( string varname, string newvalue )

Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

Parameters

varname

Not all the available options can be changed using ini_set(). There is a list of all available options in the appendix.

newvalue

The new value for the option.

Return Values

Returns the old value on success, FALSE on failure.

Related Examples ( Source code ) » ini_set




Code Examples / Notes » ini_set

tr909

[[[Editors note: Yes, this is very true.  Same with
register_globals, magic_quotes_gpc and others.
]]]
Many settings, although they do get set, have no influence in your script.... like upload_max_filesize will get set but uploaded files are already passed to your PHP script before the settings are changed.
Also other settings, set by ini_set(), may be to late because of this (post_max_size etc.).
beware, try settings thru php.ini or .htaccess.


johnzoet

[[[Editors note: Just because you're able to set something
doesn't mean it will work as expected.  Depends on the
setting.  For example. setting register_globals at
runtime will be of little use as its job has already
been completed by the time it reaches your script.
]]]
When a setting can not be changed in a user script, the return value of ini_set is "empty", not "false" as you may expect.
If you check in your script for return value is "false" the script will continue processing, although the setting has not been set.
The boolean return value is used for settings that can be changed in a script. Otherwise the empty value is returned.
To test for both error conditions use:
if (empty($blnResult) or (!$blnResult)) {
  echo "setting cannot be set";
  exit;
}


david jackson

You can also find the Apache config files by useing command httpd -V

sean

While this doesn't belong in the manual, it should be useful for people looking on this page for zend_optimizer.* ini options, which are commonly installed:
Information on the "zend_optimizer.optimization_level" and "zend_optimizer.enable_loader" options is available at:
http://www.zend.com/support/user_docs/ZendOptimizer/PDF/ZendOptimizer_UserGuide.pdf


vincent

Where you want set ini in .htaccess or vhosts directives, if the value of directive is boolean , use php_flag, else if the value is a string use php_value.
Ex : php_value include_path /home/user/include
php_flag zlib.output_compression On


ron ludwig

When your ISP does not allow you to add the default include directories - it might be useful to extend the 'include_path' variable:
<?  ini_set('include_path',ini_get('include_path').':../includes:');  ?>


brainiac5 dot php

To find the apache php settings try something like this.
> cd /etc/apache2
> grep -r -n -i  safe_mode_exec_dir *.conf
or
> grep -r -n -i safe_mode.*On *.conf
If you find a gererated file, obviously you need to find the source template for it, to change what's needed there.
I just wasted a sunny Sunday on searching for where the heck safe_mode_exec_dir was changed.
And yes, Local Value in phpinfo does mean 'changed between the php.ini file and here', as you would think.
If you have an automated virtual host configuration, such as confixx, php ini values can be spread across very many files.
They can be changed in apache config files, that can have any name, but usually will end on .conf, besides in .htaccess files.


klw

To change settings from .htaccess files, it is also required that the directory permissions configured in Apache allow this.
The <Directory /foo/bar> entry in httpd.conf MUST contain "AllowOverride All" or at least "AllowOverride Options" to read PHP settings from the .htaccess file.
E.g. in Fedora Core 2, the default settings for /var/www/html/ are "AllowOverride None", so changing PHP settings via .htaccess for applications installed below /var/www/html/ will not work.


rebootconcepts.com

set PHP_INI_PERDIR settings in a .htaccess file with 'php_flag' like this:
php_flag register_globals off
php_flag magic_quotes_gpc on


davey

If you set something using php_admin_value in httpd.conf it is then not possible to be set the value at runtime, even if it's NOT PHP_INI_SYSTEM.
Just an interesting note for Server admins this might come in handy to disable setting of certain things... like allow_url_fopen.
- Davey


miroslav

If it´s not your server and therefore you want to hide the data in your session variables from other users, it´s very useful to set the session.save_handler in your scripts to shared memory with:
"ini_set('session.save_handler','mm')".
Remember: You have to set it in every script that uses the session variables BEFORE "session_start()" or php won´t find them.


joel

I was having some trouble using include_path in my .htaccess file because I was running PHP and Apache on a windows platform.  The difference is you have to separate paths using the semicolon(;) not the colon (:)
Example:
php_value include_path ".;C:\www\scripts;C:\php\;C:\php\PEAR"


daevid

Be careful with setting an output_handler, as you can't use ini_set() to change it. *sigh*
In my php.ini I have this for my web pages (and I want it):
 output_handler = ob_gzhandler
But this causes my command line scripts to not show output until the very end.
#!/usr/bin/php -q
<?php
ini_set('output_handler', 'mb_output_handler');
echo "\noutput_handler => " . ini_get('output_handler') . "\n";
?>
root@# ./myscript.php
output_handler => ob_gzhandler
Apparently (acording to Richard Lynch):
> TOO LATE!
> The ob_start() has already kicked in by this point.
> ob_flush() until there are no more buffers.


Change Language


Follow Navioo On Twitter
assert_options
assert
dl
extension_loaded
get_cfg_var
get_current_user
get_defined_constants
get_extension_funcs
get_include_path
get_included_files
get_loaded_extensions
get_magic_quotes_gpc
get_magic_quotes_runtime
get_required_files
getenv
getlastmod
getmygid
getmyinode
getmypid
getmyuid
getopt
getrusage
ini_alter
ini_get_all
ini_get
ini_restore
ini_set
main
memory_get_peak_usage
memory_get_usage
php_ini_scanned_files
php_logo_guid
php_sapi_name
php_uname
phpcredits
phpinfo
phpversion
putenv
restore_include_path
set_include_path
set_magic_quotes_runtime
set_time_limit
sys_get_temp_dir
version_compare
zend_logo_guid
zend_thread_id
zend_version
eXTReMe Tracker