Usage and differences of Get_cfg_var () and Ini_get () in PHP

Source: Internet
Author: User
Tags php programming

PHP Get_cfg_var () and Ini_get () are functions that get configuration values, and when you need to get the configuration value of an option in php.ini, both functions are available and the results are the same.

However, there are some differences between Get_cfg_var () and Ini_get (), which is what this article is going to talk about.

Before we tell the difference between these two functions, let's look at their meanings and usage.

For the use of Ini_get (), there is a "PHP using Ini_get to obtain the value of php.ini variables," Here is no longer cumbersome.

The following is mainly about the Get_cfg_var () function.

Get_cfg_var: Gets the configuration option value for PHP.

Syntax: String Get_cfg_var (string varname);

return value: String

Content Description: If the current PHP configuration option varname is correctly obtained, the value of the variable is returned. The failure returns false.

Let's talk about the difference between the two functions.

In fact, the difference between the two functions is very distinct, and easy to learn and easy to use.

Get_cfg_var (): The value taken is the value in the configuration file
Ini_get (): The current value of the fetch

Like what

?
123 ini_set(‘SMTP‘, ‘192.160.0.24‘); // 改变 SMTP 的当前值printget_cfg_var(‘SMTP‘); // 返回 localhostprintini_get(‘SMTP‘); // 返回 192.160.0.24

Code

?
123456789101112131415 <?php/*Our php.ini contains the following settings:display_errors = Onregister_globals = Offpost_max_size = 8M*/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";//POST提交内容限制:echo ‘post_max_size+1 = ‘ . (ini_get(‘post_max_size‘)+1) . "\n"; echo ‘allow_url_fopen = ‘ . (ini_get(‘allow_url_fopen‘)) . "\n";//使用URL打开文件:?>

Output:

?
12345 display_errors = 1register_globals = 0//在我机器上什么也没有post_max_size = 8Mpost_max_size+1 = 9allow_url_fopen = 1

Code

?
123456789101112131415 <?php/*Our php.ini contains the following settings:display_errors = Onregister_globals = Offpost_max_size = 8M*/echo ‘display_errors = ‘ . get_cfg_var(‘display_errors‘) . "\n";echo ‘register_globals = ‘ . get_cfg_var(‘register_globals‘) . "\n";echo ‘post_max_size = ‘ . get_cfg_var(‘post_max_size‘) . "\n";//POST提交内容限制:echo ‘post_max_size+1 = ‘ . (get_cfg_var(‘post_max_size‘)+1) . "\n";echo ‘allow_url_fopen = ‘ . (get_cfg_var(‘allow_url_fopen‘)) . "\n";//使用URL打开文件:?>

Output

?
12345 display_errors = 1register_globals =post_max_size = 8Mpost_max_size+1 = 9allow_url_fopen = 1

In addition, here is the Ini_get_all () function, which differs from Ini_get (), where the Ini_get_all () function returns an entire PHP environment variable in the form of an array, although its usage is simple.

Ini_get_all () returns all option values as an array, so you can use them when phpinfo () is not available.

Example:

?
1234 <?php $inis= ini_get_all(); print_r($inis); ?>

Output:

?
123456789101112131415 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 ) )

I hope this article is helpful to everyone's PHP programming.

Usage and differences of Get_cfg_var () and Ini_get () in PHP

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.