Thor
Honorary Master
- Joined
- Jun 5, 2014
- Messages
- 44,236
I always create a central config file that contains all the settings and constants for the particular project and now that I am starting to make some headway I want to ensure I am doing it all according to "best practices"
Right so, assume this is my config file: (just as an example)
Now I use to just store this in a DB and then have a file called config.php which reads data from a DB and then return a array like so:
and then I just did:
However now I have been reading the php manual and been thinking of creating an INI file instead so the idea is:
config.ini (I store this outside the public folder)
and then create config.php
And then throughout my app/website I can just:
Question how do you guys go about creating and storing the config file?
Right so, assume this is my config file: (just as an example)
PHP:
define DEBUG, 0
define PRODUCTION, 1
Database hostname
Database name
Database username
Database passoword
sitetitle
public_email
public_phone
admin_email
admin_phone
app_url
app_email
app_name
Now I use to just store this in a DB and then have a file called config.php which reads data from a DB and then return a array like so:
PHP:
<?php
return array(
'host' => 'localhost',
'username' => 'root',
'password' => 'fantablikkie34',
);
and then I just did:
PHP:
<?php
$database = include('config.php');
echo $database['host']; // 'localhost'
?>
However now I have been reading the php manual and been thinking of creating an INI file instead so the idea is:
config.ini (I store this outside the public folder)
PHP:
[database]
db_name = database
db_user = user
db_password = password
and then create config.php
PHP:
$ini = parse_ini_file('config.ini');
And then throughout my app/website I can just:
PHP:
echo $ini['db_name'];
echo $ini['db_user'];
echo $ini['db_name'];
echo $ini['app_name'];
Question how do you guys go about creating and storing the config file?
Last edited: