Load variables from external file in PHP Load variables from external file in PHP php php

Load variables from external file in PHP


You can have a file with configuration and then include it on every script, like jeroen told you:

config.inc.php

$config['dbname'] = 'myDB';$config['dbuser'] = 'user';

...

then in your scripts

include_once('config.inc.php');

You could also use inheritance where you have a model for example that uses the config and then you can extend that model class.


It depends on how you want to store your configuration. You can just include a php file that has stuff like:

$config['stuff'] = "value";

but you can also use a config (ini) file or a xml file. PHP has standard functions available to read config files or xml files, so that´s easy as well.