Jump to content

Question about $_SESSION variable


A JM

Recommended Posts

When I leave the page I set my $_SESSION variable on does it survive to the next page?

 

If so, how do I clear the $_SESSION variable when I leave the page so that its only available when I'm on a specific page.

 

Thanks.

 

A JM,

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

...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']

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.