Hello, I want to declare several constants that should be accessible in all pages of a website. define (STATUS_INACTIVE, 1) define (STATUS_ACTIVE, 2) ... What is the best place to put these defines ? If i declare them in xxx.php, can i access the variables only in this specific file ? If not, how and where are constants declared best ? Regards, Fat Abbot
Simply put your contants in a file which is included in all files. Make sure the file cannot be accessed from the internet. I would use the format: define ('STATUS_INACTIVE', 1); define ('STATUS_ACTIVE', 2); . . . . In one application I have then in an init.php file, which also contains the calls to all the other files which are included in the application.
You can access them from any files included AFTER the one containing the define statements. Use the quote marks around the constant names as demonstrated otherwise it you will get a notice on PHP 5. Also you can use something like this: if (!defined('IN_APP')) die('Remote access prohibited.'); PHP: Define IN_APP in your main PHP file and that will prevent direct access to the include files. Alternatively you could name them .inc and use a permissions rule in a .htaccess file to throw a 403 on all .inc files.