|
|
 |
ini_get (PHP 4, PHP 5) ini_get -- Obtiene el valor de una opción de
configuración Descripciónstring ini_get ( string nombre_var )
Devuelve el valor de la opción de configuración en
caso de éxito. Si ocurre un fallo, como que se realice una
consulta por un valor que no existe, devolverá una cadena
vacÃa.
Cuando se consultan valores booleanos:
Un valor ini booleano de off será
devuelto como una cadena vacÃa o "0", mientras que un valor ini
booleano de on será devuelto como "1".
Cuando se consultan valores de tamaño de memoria:
Muchos valores ini de tamaño de memoria, como upload_max_filesize son
almacenados en el archivo php.ini en notación
abreviada. ini_get() devolverá la
cadena exacta almacenada en el archivo php.ini y
NO su equivalente
integer. Usar funciones aritméticas normales
sobre éstos valores no tendrÃan los resultados que
de otra forma podrÃan esperarse. El siguiente ejemplo
muestra una manera de convertir la notación corta de
bytes, de forma similar al modo que lo hace el código
fuente de PHP.
Ejemplo 1. Algunos ejemplos de ini_get() |
<?php
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 en bytes = ' . return_bytes(ini_get('post_max_size'));
function return_bytes($val) {
$val = trim($val);
$ultimo = strtolower($val{strlen($val)-1});
switch($ultimo) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
?>
|
Este script producirá:
display_errors = 1
register_globals = 0
post_max_size = 8M
post_max_size+1 = 9
post_max_size en bytes = 8388608 |
|
Vea también get_cfg_var(),
ini_get_all(),
ini_restore(), y ini_set().
Webmaster at GrimChild dot com
19-May-2006 11:34
Just thought I would add.
Very simple way of parsing data such as post_max_size
eregi_replace('[gmk]','',ini_get('post_max_size'));
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().
| |
| | Citas célebres | Un sentimental es un hombre que ve un absurdo valor en todo, y no conoce el precio fijo de nada. Oscar Wilde Escritor irlandés (1854-1900) | | Citas en tu mail | | ©Contenidos Gratis |
| Chiste de... Parejas | | Viejo y rubia | Llega este señor de unos cincuenta o sesenta años a un restaurante acopañado de una rubia despampanante, y el camarero le pregunta:
- Señor, ¿qué va a tomar?
- Un Brugal extraviejo con Perrier.
- ¿Y para la señora?
- A la señora ya le mandaré un fax esta noche. | | Chistes en tu mail | | ©ContenidosGratis |
| Inicio | Acción | Estrategia | Palabras | Puzzles | Solitarios | Foro Trucos |  | Cake Mania Jugadores: 6835 Categoría del juego: Acción Objetivo del juego: Ayuda a Jill a recuperar la pastelería de su abuela llevando su propia pastelería; consigue clientes y gana dinero. |
|  | Rainbow Web Jugadores: 2199 Categoría del juego: Puzzles Objetivo del juego: Rompe un pegajoso hechizo y salva un reino de fantasía en Rainbow Web. Tendrás toneladas de diversión mientras juegas a este mágico desafío para la mente. |
|  | Mahjongg Fortuna Jugadores: 12462 Categoría del juego: Solitarios Objetivo del juego: Velocidad y habilidad mental son las armas más importantes en esta versión de un antiguo juego asiático. Despeja el tablero lo antes posible haciendo clic en las fichas iguales y gánate la fama eterna de la puntuación más alta. |
|  | Chainz 2 Jugadores: 6955 Categoría del juego: Puzzles Objetivo del juego: Entra en el mundo de las combinaciones con Chainz 2: Relinked, emocionante secuela del exitazo del año pasado, Chainz. Gira eslabones y crea combinaciones de 3 ó más. |
|  | Delicious Jugadores: 4405 Categoría del juego: Acción Objetivo del juego: ¿Eres un as de la multitarea? ¿Quieres que tus clientes estén contentos? ¡Pues Delicious es tu juego! Sacia el apetito de los clientes y tenlos contentos; ¡no te arriesgues! |
|  | Bookworm Jugadores: 4568 Categoría del juego: Palabras Objetivo del juego: Junta las letras para formar palabras. ¡Las palabras más largas valen más puntos! |
|  | Zuma Jugadores: 4976 Categoría del juego: Acción Objetivo del juego: Controla el ídolo de la rana de piedra de los antiguos Zuma en este intrigante enigma de acción. ¡Dispara bolas para formar conjuntos de tres, pero si dejas que lleguen a la calavera dorada morirás! |
|  | Jewel of Atlantis Jugadores: 3798 Categoría del juego: Puzzles Objetivo del juego: Descubre la ciudad hundida de la Atlántida y busca valiosos tesoros. Viaja más allá de las profundidades del mar y vive trepidantes aventuras en Jewel of Atlantis. |
|  | Jewel Quest Jugadores: 3727 Categoría del juego: Puzzles Objetivo del juego: Convierte la arena de la antigua selva en oro tan rápido como puedas juntando grupos de 3 elementos. ¡Los grupos más grandes valen más puntos! |
|  | Bejeweled 2 Jugadores: 3659 Categoría del juego: Puzzles Objetivo del juego: Con cuatro modos de juego únicos y fascinantes, nuevas piezas de juego explosivas e imponentes fondos planetarios, Bejeweled 2 es mucho más adictivo que nunca. |
|
|