PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ini_restore> <ini_get_all
Last updated: Fri, 16 May 2008

view this page in

ini_get

(PHP 4, PHP 5)

ini_get — Lit la valeur d'une option de configuration

Description

string ini_get ( string $varname )

Retourne la valeur de l'option de configuration varname en cas de succès.

Liste de paramètres

varname

Le nom de l'option de configuration.

Valeurs de retour

Retourne la valeur de l'option de configuration varname en cas de succès, ou une chaîne de caractères vide si une erreur survient, ou pour les valeurs NULL.

Exemples

Exemple #1 Exemples avec ini_get()

<?php
/*
Notre fichier php.ini contient les directives suivantes :

display_errors = On
register_globals = Off
post_max_size = 8M
*/

echo 'display_errors = ' ini_get('display_errors') . "\n";
echo 
'register_globals = ' ini_get('register_globals') . "\n";
echo 
'post_max_size = ' ini_get('post_max_size') . "\n";
echo 
'post_max_size+1 = ' . (ini_get('post_max_size')+1) . "\n";
echo 
'post_max_size in bytes = ' return_bytes(ini_get('post_max_size'));

function 
return_bytes($val) {
    
$val trim($val);
    
$last strtolower($val{strlen($val)-1});
    switch(
$last) {
        
// Le modifieur 'G' est disponible depuis PHP 5.1.0
        
case 'g':
            
$val *= 1024;
        case 
'm':
            
$val *= 1024;
        case 
'k':
            
$val *= 1024;
    }

    return 
$val;
}

?>

L'exemple ci-dessus va afficher quelque chose de similaire à :


display_errors = 1
register_globals = 0
post_max_size = 8M
post_max_size+1 = 9
post_max_size in bytes = 8388608

Notes

Note: Lecture de valeurs booléennes Une directive de configuration ayant la valeur de off sera retourné sous la forme d'une chaîne vide ou "0" alors que la valeur on retournera "-1". Cette fonction peut également retourner la valeur littérale du fichier INI.

Note: Lors de la lecture des tailles de mémoire Plusieurs directives traitant de taille mémoire, comme upload_max_filesize, sont stockées dans le fichier php.ini avec une notation courte. ini_get() retourne la chaîne exacte stockée dans le fichier php.ini et NON PAS son équivalent entier. Appliquer des opérations arithmétiques classiques sur ces valeurs ne conduira à rien de bon. L'exemple ci-dessous montre une façon de convertir la notation sténographique en octets, de la même façon dont le fait le source PHP.



ini_restore> <ini_get_all
Last updated: Fri, 16 May 2008
 
add a note add a note User Contributed Notes
ini_get
filh at filh dot org
21-Nov-2005 06:24
Concerning the value retourned, it depends on how you set it.
I had the problem with horde-3 which test the safe_mode value.
THan :
- if you set the value with php_admin_value safe_mode Off (or On) ini_get returns the string
- if you set the value with php_admin_flag safe_mode Off (or On) ini_get returns the boolean.
09-Nov-2005 01:56
@marcus at synchromedia dot co dot uk

you misunderstood the comment. Of course you can use on and off, and they will work correctly.
But this entry is about *ini_get*. And if you ini_get() a value that is set to "off" in php.ini, you get returned 0 (as described above in the documentation). If you ini_get() a value that is set to "off" via .htaccess, you will be returned the string "off", which - if you use it in an if-clause, will be autoconverted to 1 (as is usual for strings).

So the problem is that which is returned by ini_get(), not what you can and cannot use in .htaccess. Sorry being unclear about this.
marcus at synchromedia dot co dot uk
05-Nov-2005 01:21
The last comment about setting values in .htaccess is not right. These lines both result in display_errors being turned off:

php_value display_errors true
php_value display_errors off

So PHP does NOT coerce the value into a boolean, but it checks for exact values of the string. These both work:

php_value display_errors on
php_value display_errors 1
31-Oct-2005 11:16
Important: The manual says that ini_get will return 0 or an empty string for boolean config values that are set to off in php.ini.

This is technically correct, however when you use

php_value register_globals off

in an .htaccess file, ini_get will return the string, which will "evaluate" to 1. So if you are using mod_php you have to check boolean config values against the strings (upper/lowercase etc.) anyhow or you will get wrong results.
david dot tulloh at infaze dot com dot au
21-Jun-2005 07:01
You can set custom entries in the ini file to provide globals such as database details.
However these must be retrieved with get_cfg_var, ini_get won't work.
Der Graph
16-Aug-2004 11:59
It might be useful for included scripts that include other files to extend the 'include_path' variable:

<?  ini_set('include_path',ini_get('include_path').':../includes:');  ?>

Sometimes, it may also be useful to store the current 'include_path' in a variable, overwrite it, include, and then restore the old 'include_path'.
fbeyer at <nospam>clickhand dot de
13-Aug-2002 07:29
If you want to test ini flags (eg. On/Off), I recommend to explicitly cast the value returned by ini_get() to boolean - it is cleaner as you only get true or false, not 0 or 1 or "" as described above.

<?php
    $register_globals
= (bool) ini_get('register_gobals');
?>

C fans may of course also cast it to (int) to play with 0 and 1 - that's also cleaner to print().

ini_restore> <ini_get_all
Last updated: Fri, 16 May 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites