Question about Session variables
Just looking for some advice to see if I'm doing something remotely correctly with Sessions.... (not something I use too often)
I basically have a simple enough database structure with two tables:
Lodges - LodgeID, Lodge, etc
Nominations - NominationID, Nomination, LodgeID, etc
A one-to-many relationship, with each Lodge being able to have multiple Nominations.
So I have a Lodge Details page, which shows the details of a selected Lodges, and a little table listing the Nominations its had.
On this page I have a link to add a new nomination, which should pick up the LodgeID of the current Lodge, so that the new Nomination is tied to the current Lodge.
So on my Lodge details page I have a session created using:
<?php
if (!session_id()) session_start();
if (!isset($_SESSION["Lodge_ID_Number"])) {
$_SESSION["Lodge_ID_Number"] = "".$row_WADAlodges['LodgeID'] ."";
}
?>
On my Add Nomination page I have a hidden field that calls up the $_SESSION["Lodge_ID_Number"]:
<input type="hidden" name="LodgeID" id="LodgeID" value="<?php echo $_SESSION['Lodge_ID_Number']; ?>" />
And on my Nomination Added page I use unset to clear that Session using:
<?php
unset($_SESSION['Lodge_ID_Number']);
?>
Hope that all makes sense.... it does seem to work, but I'm just interested to know if that's the best way of doing this, or if there's a better way?
The thing that's bugging me is what would happen if the user got as far as the Add Nomination page, and then hit the back button, went to a different Lodge, before the Session variable is cleared which might cause problems?
I'd post a link, but its in a password protected admin section of a site.