PHP's most commonly used ini function analysis for PHP. ini configuration file _ PHP Tutorial

Source: Internet
Author: User
The most common ini function analysis in PHP is for the PHP. ini configuration file. * Ini_get (): gets the option value of the configuration file. This function can be used by many people to obtain the option value in the configuration file. if it is true, 1 is returned, if it is false, * ini_get (): gets the option value of the configuration file.

This function is often 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 the string is returned.

For example, in the manual:

<? Php
/*
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"; // check whether an 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'];
}
}

Of course, you can do a lot of things for yourself.

* 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. when the script ends, this setting also becomes invalid. 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 disabled, but you need to display the error information in the program so that you can debug the program. then you can use this function:

Ini_set ("display_errors", "On ");

The program on your page will display the error information, and you can also use error_reporting to set the displayed error information level.

If you need to increase the script execution time, you can set:

Ini_set ("maid", "180 ");

Then the script execution time is changed from 30 seconds to 180 seconds by default. of course, you can also set it using set_time_limit.

In fact, if you combine ini_set and ini_get, it is very good. 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 the following two functions:

Ini_set ('include _ path', ini_get ('include _ path'). ':/your_include_dir :');

* Ini_get_all: gets all the setting option variables.

Return all option values in the form of an array, so that you can use it when phpinfo () is unavailable.

Example of a manual, for example:

<? Php
$ 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: returns the default value of the configuration file.

Is to reply to the default value of the configuration file. you can use it to restore it after setting ini_set.

Http://www.bkjia.com/PHPjc/321715.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321715.htmlTechArticle* ini_get (): gets the option value of the configuration file. This function can be used by many people to obtain the option value in the configuration file. if it is true, 1 is returned, if it is false...

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.