Jessica Posted January 31, 2007 Share Posted January 31, 2007 I have a page like this: define("ADMIN_URL", "admin/"); require_once(ADMIN_URL.'admin_menu.php'); And this works fine, the admin_menu.php is included. But in admin_menu.php I have: <li><a href="<?=ADMIN_URL?>categories/">Categories</a></li> And it prints out <li><a href="ADMIN_URLcategories/">Categories</a></li> I'm able to use the other constants I've defined on other included pages...what am I missing here? Quote Link to comment https://forums.phpfreaks.com/topic/36513-cant-use-constant-on-required-page/ Share on other sites More sharing options...
utexas_pjm Posted January 31, 2007 Share Posted January 31, 2007 Hmmm... that works for me. Are you sure that you're viewing admin_menu.php from the context of the php page where ADMIN_URL is defined? index.php: <?php define("ADMIN_URL", "foo/"); require_once(ADMIN_URL.'foo.php'); ?> foo/foo.php <?=ADMIN_URL?> From index.php output = foo/ From foo/foo.php output = ADMIN_URL Best, Patrick Quote Link to comment https://forums.phpfreaks.com/topic/36513-cant-use-constant-on-required-page/#findComment-173859 Share on other sites More sharing options...
Jessica Posted January 31, 2007 Author Share Posted January 31, 2007 I'm viewing the page which defines ADMIN_URL and that page then includes (among many other pages) admin_menu.php. Quote Link to comment https://forums.phpfreaks.com/topic/36513-cant-use-constant-on-required-page/#findComment-173912 Share on other sites More sharing options...
Jessica Posted January 31, 2007 Author Share Posted January 31, 2007 Here's a better explanation: index.php: define("ADMIN_URL", 'http://site.com/admin/'); print ADMIN_URL; //This works. require_once('header.php'); header.php: print ADMIN_URL; //This works. require_once('admin_menu.php'); admin_menu.php: print ADMIN_URL; //This does not work PS: It's PHP 5, not 4, if it matters? Edit: and finally, it appears admin_menu.php cannot see any of the variables or constants defined on index.php. This is very confusing, as I have done similar on other pages and it works fine. *grr* Quote Link to comment https://forums.phpfreaks.com/topic/36513-cant-use-constant-on-required-page/#findComment-173934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.