How can I import a variable from an external file? What I want to do is to have a configuration file in which I can write all my website settings and then to import these settings to every file, so I can set the website skin and things like that.
How can I do this?
PHP variables: Assigning by Reference PHP (from PHP4) offers another way to assign values to variables: assign by reference. This means that the new variable simply points the original variable. Changes to the new variable affect the original, and vice a verse.
php" file extension. Open up any Web browser on your desktop and enter "localhost" into the address box. The browser will open a list of files stored under the "HTDocs" folder on your computer. Click on the link to a PHP file and open it to run a script.
Look at this :
http://php.net/manual/en/function.parse-ini-file.php
you'll be happy :)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With