#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Need help in using a variable in a file


    Hi,

    i have a config file placed in folder (/root/include/config.php)

    PHP Code:
    define('SITE_BASE_PATH' '/home/techsite/public_folder/');
    define('SITE_BASE_URL' 'http://' $_SERVER['HTTP_HOST'] . '/');
    define('SERVER_TYPE''dev'); 
    Can anyone explain me what does the above line means and how is SITE_BASE_PATH and SITE_BASE_URL = getting values. (i mean what values does these variables hold)

    Another thing. i have rest of my php files (related to website ) placed in /root directory. i am using the below snippet in the code to get BASE_URL AND PATH and its not working

    Code:
    li class="menuitem"><a href="<?=SITE_BASE_URL;?>index.php">Home</a></li> 
    <li class="menuitem"><a href="<?=SITE_BASE_URL;?>display.php">Recent Research</a></li> 
    <li class="menuitem"><a href="<?=SITE_BASE_PATH;?>conferences.php">Conferences</a></li> 
    <li class="menuitem"><a href="<?=SITE_BASE_PATH;?>read.php">Publication</a></li>
    the above data is present in file (index.php) placed at /root.

    can someone kindly explain me why what i am doing wrong as i am new to php. please forgive if i have done any noobish mistakes.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,600
    Rep Power
    595
    Define simply defines variables based on whatever is contained in the second argument. Since they are just variables they do not output anything per se. You need to 'echo' them to get their values into the HTML.
    PHP Code:
    <li class="menuitem"><a href="<?echo SITE_BASE_URL;?>display.php">Recent Research</a></li>
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    those are constants, not variables. The main difference is that constants cannot be overwritten.

    He also did output the constants using that weird shorthand notation: <?= ... ?>. So the problem must be something else.

    @dazdseg: Are you sure you've actually included the file with the constant definitions in your index.php?

    Comments on this post

    • gw1500se agrees : I meant constants and I messed the
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    those are constants, not variables. The main difference is that constants cannot be overwritten.

    He also did output the constants using that weird shorthand notation: <?= ... ?>. So the problem must be something else.

    @dazdseg: Are you sure you've actually included the file with the constant definitions in your index.php?


    Yes I'm pretty sure that I've included my config file in index.php .
    Talking about weird notations ...Is my syntax wrong while outputting the constants ??

    One thing though while I'm defining these constants :

    SITE_BASE_URL..I have this variable declared $Server[HTTP_HOST] What does this mean ? How can I link my webpages with the help of this?


    @gw1500se and @Jacques1 ..Thanks a ton

IMN logo majestic logo threadwatch logo seochat tools logo