[RESOLVED] How to? Constant Variable....
How do I declare a variable (actually a base "path") and then use this in all the php files
so If I change the path I can edit ONE file.
now, i know I can do this:
define("BASEPATH", 'website.com/test/');
but how do I then use $BASEPATH in other files?
Re: How to? Constant Variable....
make one file that defines a constant, like you already showed, and require() that file in all of your other files. you can include other things in this file, like database connections for example.
the database file (database.php, perhaps):
PHP Code:
<?php
mysql_connect('localhost', 'user', 'password');
mysql_select_db('database');
define('SITE_PATH', 'http://domain.com/dir/');
?>
then, you can include the database file, and use your constant like so:
PHP Code:
<?php
require_once("database.php");
?>
Welcome to my website! The address is <strong><?php echo SITE_PATH; ?></strong>.
just remember that a constant is not a variable. you do not reference it like you would a variable; you would use SITE_PATH, not $SITE_PATH.
Re: How to? Constant Variable....