btwilkins Posted August 15, 2008 Share Posted August 15, 2008 Got a problem that I'm stuck on. I'm including a file called "page-functions.php". I wanted to use a constant for the path to the file so that I can include it from any directory. When I do that, the functions inside page-functions aren't accessible. If I take the constant out and hard code the path, my functions work. Any help would be appreciated! --- NOT Working --- settings.php <?php define("ROOT_PATH", "http://www.example.com/"); ?> page-functions.php <?php function get_test() { echo "testing!"; } ?> index.php <?php include ('settings.php'); include (ROOT_PATH . 'includes/page-functions.php'); get_test(); ?> -- Working -- index.php <?php include ('settings.php'); include ('includes/page-functions.php'); get_test(); ?> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/119871-solved-functions-arent-accessible-when-using-a-constant-in-an-include-path/ Share on other sites More sharing options...
akitchin Posted August 15, 2008 Share Posted August 15, 2008 using the HTTP protocol to include files forces PHP to interpret it as straight content, no PHP. try changing ROOT_PATH to a local link and try again. Link to comment https://forums.phpfreaks.com/topic/119871-solved-functions-arent-accessible-when-using-a-constant-in-an-include-path/#findComment-617517 Share on other sites More sharing options...
dbo Posted August 15, 2008 Share Posted August 15, 2008 You can't do includes that way. You need to specify the address as though it were local on the machine. define("INCLUDE_PATH", "/var/www/includes/"); include_once INCLUDE_PATH . "my_script.php"; This should work. Link to comment https://forums.phpfreaks.com/topic/119871-solved-functions-arent-accessible-when-using-a-constant-in-an-include-path/#findComment-617518 Share on other sites More sharing options...
wildteen88 Posted August 15, 2008 Share Posted August 15, 2008 define("ROOT_PATH", "http://www.example.com/"); should be define("ROOT_PATH", $_SERVER['DOCUMENT_ROOT']); Link to comment https://forums.phpfreaks.com/topic/119871-solved-functions-arent-accessible-when-using-a-constant-in-an-include-path/#findComment-617520 Share on other sites More sharing options...
btwilkins Posted August 15, 2008 Author Share Posted August 15, 2008 That worked... many thanks! Link to comment https://forums.phpfreaks.com/topic/119871-solved-functions-arent-accessible-when-using-a-constant-in-an-include-path/#findComment-617575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.