RE: [PHP] Best way to set global params for entire site??

From: Date: Tue, 22 Oct 2002 20:17:31 +0000
Subject: RE: [PHP] Best way to set global params for entire site??
Groups: php.general 
Request: Send a blank email to php-general+get-120976@lists.php.net to get a copy of this message
I also prefer using constants for the reason you don't need to store them in a global scope and they are read only which prevents your script from changing the configuration. If you need to change the configuration be selective about how you declare your constants for example: session_start(); if ($_SESSION['settings']['onlinehelp'] == 0) { define('ONLINE_HELP_ENABLE', 0); } else { define('ONLINE_HELP_ENABLE', 1); } Basically this enables online help by default, unless the user has disabled it. The $_SESSION['settings'] array gets populated when the user logs in, this way you can have a default configuration but still allow users to override select settings while using constants for your configuration file. Jason -----Original Message----- From: John Nichel [mailto:jnichel@by-tor.com] Sent: Tuesday, October 22, 2002 1:41 PM To: Monty Cc: php-general@lists.php.net Subject: Re: [PHP] Best way to set global params for entire site?? One way or the other, you're going to have to do something on every page. Personally, I use constants in a config file for something like this, and require_once the config file on every page. Another possible way would be to set your default settings in a session when a visitor first comes to the site, but this would just be extra work since you would also have to check if the variables are set, and if not set them, on each page. define ( "VarName", "VarValue" ); echo ( VarName ); This will even be available inside of functions without having to use the global keyword. The only drawback is that you will not be able to change the value of VarName on that page. Monty wrote: > I'm building a site with PHP and most scripts need access to certain > site-wide global parameters, such as paths and default settings, etc. What's > the best way to load this information so that it's globally available to all > scripts? I have a func.php file that is included in all scripts - do I just > load them every time for each script in there? Or is there a more efficient > way of doing this with environment variables or some other way? > > Thanks!! > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#120976) next »