Reputation: 490
I'm using two $_SESSION
variables on one of my web pages. These are extremely crucial as they control how data is manipulated. Right now, when the user leaves that page and loads another, I'm resetting the two $_SESSION variables = 0
on each loading page.
My question: Is there a way, maybe in JQuery or something, that I can detect when a user leaves that web page for another and then reset the variables that way, instead of doing it across some 50 pages as I'm doing now? To me, this would be a cleaner approach.
At the top of every page but the one in question, this is what I'm doing using PHP to reset the two variables:
<?php
$_SESSION['var1'] = 0;
$_SESSION['var2'] = 0;
?>
Upvotes: 3
Views: 60
Reputation: 4481
The standard way of doing this in PHP
would be to have a "header" file which you include on every single page IMHO:
<?php
include_once "header.inc.php";
// .....
?>
Such a header file is usually used to manage database-connections and also session-variables like in your case.
By starting every single page with including this header file, you can easily change "global stuff" later on.
Upvotes: 2