How do I store configuration information in the INI file?

Source: Internet
Author: User
How do I store configuration information in the INI file?

Some of the information that is reused in the site (such as passwords, paths, and variables) is best stored in a file so that if you need to move the code to another site, you only need to modify the settings once, instead of hundreds or thousands of code changes, how do you store those configuration letters in the specified file? And how do you read these configuration information?

The simplest way to store configuration information is to create a variable in an. ini file, and then use the Parse_ini_file function to include the file in your code, and the function to parse files in the same format as php.ini, including, The following is a config.ini file, which reads as follows:

; This is a MySQL configuration file; Comments start with ";", as in php.inihost = Localhostdaname = Db_databaseusername = root    password = Rootcharset  = Usf8

Apply the Parse_ini_file function to read the data in the configuration file Config.ini, with the following code:

<?phpheader ("content-type:text/html; Charset=utf-8 "), $ini _array = Parse_ini_file (" Config.ini ");p Rint_r ($ini _array); $ini _array = Parse_ini_file (" Config.ini ", True);p Rint_r ($ini _array);? >

The output looks like this:

When storing a profile, it is best not to store the profile in the Web root, because the profile typically contains user name and password information, and if the profile is stored with the Web root, it is easy to be accessed by "uninvited visitors" to steal important information, so it should be stored outside the server so that " Uninvited visitors "It's hard to access this file.

If you must store the configuration file under the Web root, be sure to include a file directive in the. htaccess file that restricts the users who have access to the class file!

How to store configuration information in a file we come here to the end of the introduction, I believe that the small partners can master the sub-knowledge points, the small partners will be able to contact their own local, to consolidate the knowledge they have mastered!

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.