Jump to content

Question about $_SESSION variable


A JM

Recommended Posts

Since the variable would be "super-global" its perfect for keeping my variable but when I leave the page I want it to be deleted. Is there like some type of exit function() to erase the variable?

 

The page that I would be changing to would also have a session_start() on it.

 

Thanks,

...when I leave the page I want it to be deleted....

 

In that case SESSION is the wrong choice!

If you really think you need a superglobal variable (which, in most cases is a bad idea).

Simply define it in the global scope (outside all function and classes) and then call it anywhere in the script like that:

$GLOBAL['var_name']

 

An individual variable in the $_SESSION array will be cleared when you either unset it, set it equal to NULL or when the Session ends.

 

A Session will end when you either call session_destroy(), when the user closes the browser, or when the Session times out.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.