Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:49:25+00:00 2026-06-14T19:49:25+00:00

How can I unset SESSION[‘variables’] when user is leaving a page, without having to

  • 0

How can I unset SESSION['variables'] when user is leaving a page, without having to include something on the top of every single page which I have on my site?

Any best practises around you might know of?

Thanks.

EDIT

I have a wizard for setting up a company and a customer.This includes 2 pages: 1 for company and 1 for customer. If the user wants to re-use the data filled in at the company for the customer, he can check the checkbox and when form at page 1 (company) is posted, at page 2 (customer) those fields are automatically set (think about fields like: postal adress, street, phone etc.). The user can access page 1 and page 2 whenever he wants, so I have to unset the session else it will keep auto-filling in the fields.

I can unset the session after the fields are set on page 2, but when he refreshes the browser, the fields become empty again. This is not a big problem ofcourse, but isn’t there an easy way to only unset these sessions when the user goes to any other page (without exiting browser and within my website)?

EDIT

My code:

Company page:

$_SESSION['wizard2']= "true"; // used for manipulating page when entering in wizard mode
if (isset($_POST['savedata'])) // if user wants to re-use data from page1
{
$_SESSION['savedata'] = "true";
$_SESSION['custprovincesession']=mysql_real_escape_string($_POST['compprovince']);
header("Location:customer_page.php");
exit();

Customer page:

if (isset($_SESSION['wizard2'])) // used for manipulating page when entering in wizard 
{
    unset ($_SESSION['wizard2']);
}
if (isset($_SESSION['savedata'])) // if user wants to re-use data from page1
{
    $_SESSION['wizard3'] = "true";
}


  <tr>
    <th><label for="custprovince">Province:</label></th>
    <th><input type="text" name="custprovince" style=width:200px id="custprovince" size="8" value="<?php if (isset($_SESSION['wizard3']))   {   echo $_SESSION['custprovincesession'];}?>"/></th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>

at the end of page 2:

if (isset($_SESSION['wizard3']))
{
    unset ($_SESSION['wizard3']);
    unset ($_SESSION['custprovincesession']);
}

Because of this, by refreshing the page the sessions are unset. Is there no other way to unset these sessions when the user leaves the “customer_page.php”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:49:26+00:00Added an answer on June 14, 2026 at 7:49 pm

    This might be a silly question, but why would you want to unset certain session variables on every page?

    Surely the point of the session is to persist across page views, and thus you would only want to unset or clear it at specific trigger points (such as a user logging out of the system.

    To answer the question, many frameworks would generally use a single entry point for all scripts, which does any initialisation, farms off the actual page work to a controller, and then return to the single entry point. If you use this methodology then you can put any closing logic at the end of the page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to unset one variable in current user session then I can
Possible Duplicate: Destroy or unset session when user close the browser without clicking on
I need to unset my session variables, when PayPal returns IPN. The simplest script
Can I unset with wildcard? I have a bunch of $_SESSION variables which all
I have this page which when opened just reads in some session variables and
im trying to wrote a code where i can remove variables from a session
How do I remove a tcl procedure? One can unset a variable, override an
Why can't I unset a variable in a foreach loop? <?php $array = array(a,s,d,f,g,h,j,k,l);
I'm having problem with going from mobile page to main page implemented in Joomla
What is the difference between destroying a session and removing its values? Can you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.