January 23rd, 2013, 06:14 AM
Need help in using a variable in a file
i have a config file placed in folder (/root/include/config.php)
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)
define('SITE_BASE_PATH' , '/home/techsite/public_folder/');
define('SITE_BASE_URL' , 'http://' . $_SERVER['HTTP_HOST'] . '/');
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
the above data is present in file (index.php) placed at /root.
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>
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.
January 23rd, 2013, 06:59 AM
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.
<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.
January 23rd, 2013, 07:08 AM
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
January 24th, 2013, 12:07 AM
Originally Posted by Jacques1
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