For example, the following settings are included in the php.ini file:
The code is as follows |
Copy Code |
Register_globals = Off Post_max_size = 8M |
In the PHP section we can get this:
The code is as follows |
Copy Code |
<?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 in bytes = '. Return_bytes (Ini_get (' post_max_size ')); ?> |
If you want to get the value of the variable in the entire php.ini, we can use the Ini_get function Ini_get_all ()
The Ini_get_all () function returns the entire PHP environment variable as an array
Of course, if you just want to know the configuration information for PHP
<?php
Phpinfo ();
?>
Then look down.
There is an example in the PHP manual
The code is as follows |
Copy Code |
<?php /* Our php.ini contains the Following settings:
Display_errors = On Register_globals = Off Post_max_size = 8M */ echo ' display_errors = '. Ini_get (' display_errors '). "\ n"; Show whether the error is turned on echo ' register_globals = '. Ini_get (' register_globals '). "\ n"; Whether the global variable is open echo ' post_max_size = '. Ini_get (' Post_max_size '). "\ n"; Maximum file size to submit echo ' post_max_size+1 = '. (Ini_get (' post_max_size ') +1). "\ n"; ?> |
Output:
Display_errors = 1
register_globals = 0
Post_max_size = 8M
Post_max_size+1 = 9
PHP configuration Function Ini_get () is mainly to obtain the configuration file, you can facilitate a lot of operations. For example, you want to manipulate string filtering, but it's not clear if MAGIC_QUOTES_GPC is open, so you can write a function like this:
The code is as follows |
Copy Code |
/* String Filter function * * function Stringfilter ($STR) { if (Ini_get (' magic_quotes_gpc) ') { return $str; } else { Return addslashes ($STR); } } |
Of course, if you don't know if your global variable is open, you can also customize such a function:
/* Variable detection function * *
The code is as follows |
Copy Code |
function Getgetvar ($var) { if (Ini_set (' register_gobals ')) { return $var; } else { Return $_get[' var ']; } }
|
Of course, you can use the PHP configuration function ini_get () do a lot of use, you slowly experience.
Add
1.ini_get () Get configuration parameters, Ini_set () set configuration parameters
The code is as follows |
Copy Code |
<?php echo ini_get (' display_errors '); 1 Dynamically modifying php.ini configuration information, invalidation after script execution Ini_set (' Display_errors ', 0); echo ini_get (' display_errors ');//0
|
2.ini_get_all () Get all configuration information
The code is as follows |
Copy Code |
<?php Print all configuration information, huge number ... Print_r (Ini_get_all ());
|
3.ini_restore () Restore configuration information to original value
code is as follows |
copy code |
<?php Echo ini_get (' display_errors ');//1 //Dynamic Modify php.ini configuration information, invalid script after execution Ini_set (' display_errors ', 0); Ini_ Restore (' display_errors '); Echo ini_get (' display_errors ');//1 |