|
-
Sep 30th, 2009, 08:37 AM
#1
[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?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 30th, 2009, 10:41 AM
#2
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.
-
Sep 30th, 2009, 11:28 AM
#3
Re: How to? Constant Variable....
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|