Several configuration file functions in PHP

Source: Internet
Author: User

 

I have never paid much attention to it before. I have heard from my colleagues today and can check it out immediately. It is very powerful.
Php configuration functions are several ini _ * functions, mainly for configuration file operations. In fact, there are 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 believed to have been used by many people 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 mainly used to obtain the configuration file and facilitate many operations. For example, if you want to filter strings, but do not know 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'];


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.