Configuring a script by changing variables inside a script is a bad idea.
The easiest way to save configuration settings is to use the .ini file and parse it using the parse_ini_file function. http://php.net/manual/en/function.parse-ini-file.php
sample ini:
[db] host = "foo.org" user = "dbguy" [session] timeout = 600
If your script object is oriented, you should wrap the configuration setting in the class ... and pass it as a constructor argument to your main class.
Otherwise, you can use the global array, but please do not use the 'global' keyword in your functions! Your functions should accept settings from your functions as parameters.
$config = parse_ini_file("protectedFolder/config.ini", true); //wrong, do not do it this way function connect(){ global $config; $connection = dostuff($config['db']['user'],$config['db']['host']; //do stuff } connect(); //right function connect2($user, $host){ $connection = dostuff($user, $host); //do stuff } connect2($config['db']['user'], $config['db']['host']);
This is a very simple concept, and there are more efficient ways to do this, but you need to get started, and it will work for simple applications.
If you need something more complicated, you should google for "dependency injection"
EDIT: edited comments EDIT2: fixed missing quotes
source share