简体   繁体   中英

Making a Config.php file

I'm probably going to sound horrible with this but i'm going to try.

I want to take a user's defined information from a form and place it into a config.php file, you know, like "Site Title" and they would enter in whatever and it would permanently place it into a config file so that it was dynamic. So instead of it setting it as a one time placement, using a variable it would make it into another variable in the config.php. I hope that makes sense,

So it would be like if I entered "Site Webmaster" into a simple form and then it would go to the config.php and place down "$sitetitle = "Site Webmaster" into the config so I could just include it into other pages.

Would it be better do that way or through MySql?

Strictly speaking, you can store config data in a .ini file and read the file with the parse_ini_file function. Assume you have 2 files, all stored in the same folder: - config.ini - parse.php

config.ini contains your config values:

Site Title = foo
Site Address = foo.com.

parse.php contains the method to read the ini file:

<?php
var_dump(parse_ini_file("config.ini"));
?> 

The php file will return:

array (size=2)
  'Site Title' => string 'foo' (length=3)
  'Site Address' => string 'foo.com' (length=7)

However this might raise performance issues because you might read the file every time you want to know the values. I would suggest to prefer the use of constants, or at least store the config values into constant at the start of your procedure:

define('SITE_TITLE', 'foo');
define('SITE_ADDRESS', 'foo.com'); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM