Page 1 of 1

How long does a variable last?

Posted: Wed May 12, 2004 9:48 am
by Fusion
The title explains it all. Does it just last untill the php is closed? Or untill it is assigned another value? I would like to make it so that in the header, it sets variables, but how do I make sure that it stays throughout the wholepage? Should I use a session? and if yes, how should I do it? make it so the seasson ends when the client goes to another page?

Thanks for your responce!

Posted: Wed May 12, 2004 9:52 am
by launchcode
A variable will exist until one of two things happens:

1) You destroy it (usually via unset)
2) Your script terminates.

If you want to pass it from PAGE to PAGE then you need to consider using a session or serialised object.

Posted: Wed May 12, 2004 11:52 am
by dave420
or shared memory, or a database, or a flat file, or any number of ways :)

Posted: Wed May 12, 2004 1:01 pm
by launchcode
True.. except all of those things require that you've maintained state between the pages in order to be able to extract the stored variable again.. ;)

Posted: Fri May 14, 2004 10:35 am
by dave420
Very true :)