Jump to content

unset session on leaving a certain page


AdRock

Recommended Posts

This is probably really easy but what i want to do is unset a session when the user changes page.

 

This session should only be used on a certain page.

 

would it be something like

 

if($_SERVER['PHP_SELF']) !="mypage.php") unset $_SESSION['thissession'];

Link to comment
Share on other sites

This is probably really easy but what i want to do is unset a session when the user changes page.

 

This session should only be used on a certain page.

 

would it be something like

 

if($_SERVER['PHP_SELF']) !="mypage.php") unset $_SESSION['thissession'];

 

Use unset($_SESSION['somevariable']) to delete a specific session variable. If you want to delete the entire session then use session_destroy() which will kill the session completely.

 

Or, you could just not include session_start() on the pages that don't need the session data.

Link to comment
Share on other sites

On the page you want to use sessions create the session and add the CREATE_URI (=$_SERVER['REQUEST_URI']) variable then on the other pages add this code:

 

if (isset($_SESSION['CREATE_URI']) && $_SESSION['CREATE_URI'] !== $_SERVER['REQUEST_URI']) {
   unset($_SESSION['CREATE_URI']);
}

Link to comment
Share on other sites

Right I've been playing around and this only works on the same url such as

 

mypage.php?thisvar=1&thatvar=2

 

If i add another var to the end of the url, the session gets unset becuase the url isn't exactly the same.

 

What this is for is filtering results so i can choose how many results to display and the order wether it's asc or desc and I need to use paging which all works except the url changing from

 

mypage.php?thisvar=1&thatvar=2

 

to

 

mypage.php?thisvar=1&thatvar=2&pagenum=2

 

unsets the session

 

 

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.