rbrown Posted August 8, 2011 Share Posted August 8, 2011 I can't figure this out... Trying set the constant on the first page which is at: /acl/redirect.php define('PATHTOINCLUDES', dirname($_SERVER["SCRIPT_FILENAME"])); /* include the functions and config files */ include (PATHTOINCLUDES.'/config.php'); include (PATHTOINCLUDES.'/functions.php'); Then it redirects to: /acl/admin/adminpage.php And the adminpage.php has the two include lines and I'm getting: Notice: Use of undefined constant PATHTOINCLUDES - assumed 'PATHTOINCLUDES' in C:\a\UniServer\www\acl\admin\adminpage.php on line 9 Warning: include(PATHTOINCLUDES/config.php) [function.include]: failed to open stream: No such file or directory in C:\a\UniServer\www\acl\admin\adminpage.php on line 9 I have error_reporting = E_ALL set in the php.ini so it makes sure I write code with defined vars and no errors. So I'm not getting why I'm getting the notice since I do have the Constant quoted in the define statement and why it isn't being passed to the next page. I did have session vars and anti page caching code and I ripped all that out of the code thinking that was a problem... but didn't make any difference. Or am I missing something else? Quote Link to comment https://forums.phpfreaks.com/topic/244202-constant-not-holding/ Share on other sites More sharing options...
the182guy Posted August 8, 2011 Share Posted August 8, 2011 Looks like your just not including the script that has the define() stamement, into adminpage.php Constants won't persist across page requests like session variables do. They need to be included into every script that accesses them. Quote Link to comment https://forums.phpfreaks.com/topic/244202-constant-not-holding/#findComment-1254157 Share on other sites More sharing options...
rbrown Posted August 8, 2011 Author Share Posted August 8, 2011 I see... I missunderstood how they worked. Was trying something different... Instead of hard coding the includes on every page, like I normally do, was trying to make them all the same. I'm fixing code someone else wrote. There are a ton of pages and directories... It's a real mess... So I guess I'll try sessions and see how that works. Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/244202-constant-not-holding/#findComment-1254166 Share on other sites More sharing options...
the182guy Posted August 8, 2011 Share Posted August 8, 2011 Storing include locations in the session could be a bad idea. What happens if the session expires or doesn't exist and a user views a page that doesn't have the vars being set? If there's a script that all of the others are including, such as a database connection script then you could put your constants and other includes there, so they'll be present on all pages that include that script. Quote Link to comment https://forums.phpfreaks.com/topic/244202-constant-not-holding/#findComment-1254171 Share on other sites More sharing options...
rbrown Posted August 8, 2011 Author Share Posted August 8, 2011 True... but it does have session checking so if the session expires it takes them back to the login page where the include would be reset. So I'm thinking that would / should work. I'm also thinking about writing a script to figure out where the calling page is in relation to the includes pages. I'll probably do that instead since I thinking about putting the config file below web root. Quote Link to comment https://forums.phpfreaks.com/topic/244202-constant-not-holding/#findComment-1254209 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.