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

 

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.

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']);
}

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

 

 

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.