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!