Forum Moderators: coopster

Message Too Old, No Replies

Advice on Constants - Notice: Undefined Constant

How to handle PHP constants

         

The_Warden

5:53 pm on Apr 9, 2003 (gmt 0)

10+ Year Member



I'm currently developing a web site that stores two security levels of the client logged in. These security levels and including a few other variables are returning a PHP notice statement, "Notice: Undefined constant...". Now these variables are set at initial login into the web site and are stored into a the session file to reduce security checking routines and with the concept of why do a check again when we already know the value.

To resolve this PHP notice issue I figured no big deal I will just declare the variable as a constant using define(). But by doing this correct me if I'm wrong you now no longer refer to the variable with a dollar sign and the variable name. Which is fine but can I store the constant into the session file?

My concern and question is what the best direction to resolve this? At present if I just define the variables as a constant I get another PHP message "Notice: Undefined offset..." throughout my code when referencing my session variable (_SESSION[name]).

Any advice would be greatly appreciated.

mavherick

9:38 pm on Apr 9, 2003 (gmt 0)

10+ Year Member



I'm not totally sure I understand what you're trying to do, so let me know if I get things right:

When the user login and is valid you set a bunch of sessions variable like ($_SESSION['securitylevel1'])

After that do you define constants for a few of those like this:

define("SECURITY_LEVEL_1", $_SESSION['securitylevel1']);

As long as the define statements precede any code where you use the constants, it should work.

like if (SECURTITY_LEVEL_1 > 10)

hope I'm not too off track

mavherick