The current security setting does not allow the download of the file The most commonly used four INI functions in a PHP configuration file

Source: Internet
Author: User
PHP configuration function is a few ini_* functions, mainly for the operation of the configuration file, in fact, four functions: Ini_get, Ini_set, Ini_get_all, Ini_restore. The most useful thing about personal feeling is ini_set and ini_get.
* Ini_get (): Gets the option value of the configuration file
This function believes that many people have, that is, to get the value of an option in the configuration file, if the value of True returns 1, if the value of False returns 0, the string returns a string.
For example in the Handbook:
/*
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 if the error is open
echo ' register_globals = '. Ini_get (' register_globals '). "n";//whether the global variable is open
echo ' post_max_size = '. Ini_get (' Post_max_size '). "n";//File size can be submitted at most
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
This function is mainly to get the configuration file, you can easily do a lot of things. For example, you want to manipulate string filtering, but it's unclear if MAGIC_QUOTES_GPC is open, so 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 don't know if your global variables are open, you can also customize such a function:
/* 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 use, you slowly experience.
* Ini_set function: Set some variable values in the PHP.ini
This function is the value in the SET option, which takes effect after executing the function, and this setting is invalidated when the script ends. Not all options can be changed by the function set. The specific values can be set and the list in the manual can be viewed.
is the ability to set the option values in the php.ini for example, the Display_error option is off, but you want to display the error message in the program, so that you can debug the program, then use this function:
Ini_set ("Display_errors", "on");
Then the program on your page will display an error message, and you can also use error_reporting to set the level of error messages displayed.
If you need to increase the script execution time, you can set:
Ini_set ("Max_execution_time", "180");
Then the script execution time is changed from the default of 30 seconds to 180 seconds, of course, you can also use Set_time_limit () to set.
In fact, you put Ini_set and ini_get together so that, very good. For example, if you want to add your own file path to the config file, but you have no permission to change php.ini, you can combine two functions:
Ini_set (' include_path ', Ini_get (' include_path '). ':/ Your_include_dir: ');
* Ini_get_all: Get all the settings option variables
Returns all option values as an array, so you can use them when the phpinfo () is not available.
Examples of manuals, such as:
$inis = Ini_get_all ();
Print_r ($inis);
?>
Partial output:
Array
(
[Allow_call_time_pass_reference] = = Array
(
[Global_value] = 1
[Local_value] = 1
[Access] = 6
)
[Allow_url_fopen] = = Array
(
[Global_value] = 1
[Local_value] = 1
[Access] = 7
)
...
)
* Ini_restore: Reply to configuration file default value
is to reply to the default value of the configuration file, which you can use to recover when you use the Ini_set setting.

The above describes the current security settings do not allow the download of the file PHP configuration file The most commonly used four INI functions, including the current security settings do not allow the download of the file content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.