Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSurendra Kulkarni
6,826 PointsNeed help Constants are not recognised in header.php
I have coded config.php file like so:
define("BASE_URL", "/shirts4mike-Pr02-St02/");
define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT"] . "/shirts4mike-Pr02-St02/");
and in cluded it in receipt/index.php like so: '''php <?php require_once "../inc/config.php"; //relative path
$pageTitle = "Thank you for your order!"; $section = "none"; include(ROOT_PATH . "inc/header.php"); ?>'''
receipt/index.php works however if I substitute constants in header file like so: ''' <head> <title><?php echo $pageTitle; ?></title> <link rel="stylesheet" href="<?php echo BASE_URL;?>css/style.css" type="text/css"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css"> <link rel="shortcut icon" href="<?php echo BASE_URL;?>favicon.ico"> </head>'''
I get the warning message undefined variable BASE_URL
) Notice: Use of undefined constant BASE_URL - assumed 'BASE_URL' in C:\xampp\htdocs\shirts4mike-Pr02-St02\inc\header.php on line 9 Call Stack #TimeMemoryFunctionLocation 10.2020138904{main}( )..\index.php:0 20.2030142272include( 'C:\xampp\htdocs\shirts4mike-Pr02-St02\inc\header.php' )..\index.php:4 BASE_URLcss/style.css" type="text/css"> ( ! ) Notice: Use of undefined constant BASE_URL - assumed 'BASE_URL' in C:\xampp\htdocs\shirts4mike-Pr02-St02\inc\header.php on line 11 Call Stack #TimeMemoryFunctionLocation 10.2020138904{main}( )..\index.php:0 20.2030142272include( 'C:\xampp\htdocs\shirts4mike-Pr02-St02\inc\header.php' )..\index.php:4 BASE_URLfavicon.ico">
Any help will be greatly appreciated.
5 Answers
miguelcastro2
Courses Plus Student 6,573 PointsTry putting your require_once(config.php) at the top of your header.php include.
Surendra Kulkarni
6,826 PointsThanks Miguel
I have tried inserting config.php but it gives me the following ( ! ) Notice: Use of undefined constant BASE_URL - assumed 'BASE_URL' in C:\xampp\htdocs\shirts4mike-Pr02-St02\inc\header.php on line 4
Hee is the code
<?php
require_once ('config.php');
var_dump(BASE_URL);
?>```
Thanks again and happy Christmas!
miguelcastro2
Courses Plus Student 6,573 PointsYour code should work as it looks proper. The only thing I would suggest is to slowly step through it to make sure the constant is being declared before you call it. Add echo statements to your code to step through the value of the constant as your script runs. You can also use the die() command to kill the script at certain points to see what the value of BASE_URL was at a certain point.
My last suggestion is to use single quotes like this:
define('BASE_URL', '/shirts4mike-Pr02-St02/');
Surendra Kulkarni
6,826 PointsThanks I'll give it a go!
1v4n
4,584 PointsWas there an answer to this? I'm having the same issue