Several configuration file functions in php have never been noticed before. let's hear from my colleagues today and check out the functions.
The configuration function of php is several ini _ * functions. it is important to control the configuration file. there are actually four functions: ini_get, ini_set, ini_get_all, and ini_restore. The most useful ones are ini_set and ini_get.
* Ini_get (): gets the option value of the configuration file.
This function is trusted by many people. it is used to obtain the value of an option in the configuration file. if it is true, 1 is returned. if it is false, 0 is returned, and a string is returned.
For example, in the manual:
/*
Our php. ini contains the following settings:
Display_errors = On
Register_globals = Off
Post_max_size = 8 M
*/
Echo 'display _ errors = '. ini_get ('display _ errors'). '\ n'; // whether the display error is enabled
Echo 'register _ globals = '. ini_get ('register _ globals').' \ n'; // whether the global variable is enabled
Echo 'post _ max_size = '. ini_get ('post _ max_size'). '\ n'; // maximum file size that can be submitted
Echo 'post _ max_size 1 = '. (ini_get ('post _ max_size') 1). '\ n ';
?>
Output:
Display_errors = 1
Register_globals = 0
Post_max_size = 8 M
Post_max_size 1 = 9
This function is important to get the configuration file, which can be easily controlled by you. For example, if you want to control string filtering, but do not understand whether magic_quotes_gpc is enabled, you can write a function like this:
/* String filter function */
Function stringFilter ($ str)
{
If (ini_get ('Magic _ quotes_gpc )'){
Return $ str;
} Else {
Return addslashes ($ str );
}
}
Of course, if you cannot know whether your global variables are enabled, you can also customize the following functions:
/* Variable detection function */
Function getGetVar ($ var)
{
If (ini_set ('register _ gobals ')){
Return $ var;
} Else {
Return $ _ GET ['var'];
}
}
Of course, you can do a lot of useful work and understand it slowly.
* Ini_set function: set certain variable values in php. ini.
This function is the value in the setting option. it takes effect after the function is executed, and the setting is invalid when the script ends. Not all options can be changed to function settings. You can set specific values to view the list in the manual.
You can set the option value in php. ini. for example, the display_error option is closed, but you need to display the error information in the program so that you can debug the program. then you can apply this function:
Ini_set ('display _ errors ', 'on ');
The program on your page will display the error information, and you can also apply error_reporting to set the displayed error information level.
If you need to increase the script fulfillment time, you can set:
Ini_set ('max _ execution_time ', '123 ');
The script execution time is changed from 30 seconds to 180 seconds by default. of course, you can also set it by using set_time_limit.
It is really good if you use ini_set and ini_get together. For example, if you want to add your own include file path in the configuration file, but you have the permission to change php. ini, you can combine two functions: