views:

14

answers:

1

I am trying to not let my session variables balloon out of control, espeically since some carry heavey objects.

In the application I am developing there are 3 major items that can be searched on; let's say, people, cars, and pets. Each has a search screen and results (stored in sessions) which can be sorted and paged. When I go to the details page of one of the items, I want to be able to easily go back to my search results. However, if I go to any other page, say I jump to pets or an About Us page, I want to kill the session variable I was just working on. However, I want to avoid a function at the beginning of each screen to do this. Is there a better way to manage one's session variables?

A: 

You could nest them in arrays:

$_SESSION['results'][$item_id]['results_thing'];

This is a pretty normal thing to do. You will have to have some header that unsets variables. That's unavoidable - in order to do something, you need some code.

Borealid