Results 1 to 3 of 3

Thread: [RESOLVED] How to? Constant Variable....

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Resolved [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"

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  3. #3

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How to? Constant Variable....

    Ahh right! thanks!!
    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
  •  



Click Here to Expand Forum to Full Width