How do you access constant values when using them in a statement? define('account_id','2'); this does not work: if isset(account_id) nor does if (constant(account_id) < 2) yada yada Ideas or good tutorials for constants? The PHP website is more then unhelpful on this topic.
define('account_id','2'); if (account_id == 2) { // account_id is 2 } PHP: By convention, contants are usually uppercase
isset won't work as it's not a variable, it's a constant. As exam noted, all you have to do is use it like a variable or any other value. If you ever need to determine whether or not a constant is actually defined or not, you can call defined('CONSTANT_NAME')).
oh how interesting then! I have never used constantants this way, I am use to assigning them as a variable, ie String Const foo; From C# etc. Thank you very much for the help, and the capitalization is duely noted as well
Also, I will assume (since I am using account_id as a constant), when the user is not logged in... define('ACCOUNT_ID',null); correct?
PHP doesn't use constants the same way C# does, for example. In C#, you modify a variable with the const modifier to say 'hey, this variable is not allowed to change'. In PHP, well, it works the same way, but you don't use them like that. PHP constants are more for what in C# you would use a #define or enum for. In PHP, constants are used to remove 'magic numbers' and so on. Technically, you could do what you're suggesting but in practice, you really, really shouldn't. It just not how things are done in PHP. In practice, you should just use variables as you do normally, but don't expect to be able to enforce their immutability. I hope that makes a bit of sense!
Yeah, my biggest want for the use of it is for holding something in a global scope, because of things being OOPS based. It's just a thing of me being lazy I guess, so that I dont spend 2 hours working on something, then realizing the only reason I can't get the variable to work is because I forgot to global it.
You could use this for your account/authentication code, but you should probably read up on php sessions and just store the info in the super global $_SESSION array.
I about about $_SESSION and have used it vastly. I am not sure what sparked this change, but for some reason I wanted to stay away from using sessions with this script. I think it is because I have been programming in vbulletin world to long, heh. Another reason I wanted to avoid the $_SESSION was the 15 minute timeout setting. It becomes rather annoying at times.