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

  • Home
  • SEARCH
  • 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 917839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:16:31+00:00 2026-05-15T18:16:31+00:00

I need to destroy a session when user leave from a particular page. I

  • 0

I need to destroy a session when user leave from a particular page. I use session_destroy() on the end of the page but its not feasible for me because my page has pagination. My page is: abc.php?page=1 or abc.php?page=2 or abc.php?page=3.

So, I need to destroy a session when a user leaves from abc.php page. How can I do it without using a cookie?

  • 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-05-15T18:16:32+00:00Added an answer on May 15, 2026 at 6:16 pm

    Doing something when the user navigates away from a page is the wrong approach because you don’t know if the user will navigate to a whole different page (say contact.php for the sake of the argument) or he/she will just go to the next page of abc.php and, as Borealid pointed out, you can’t do it without JS. Instead, you could simply add a check and see if the user comes from abc.php:

    First, in your abc.php file set a unique variable in the $_SESSION array which will act as a mark that the user has been on this page:

    $_SESSION['previous'] = basename($_SERVER['PHP_SELF']);
    

    Then, add this on all pages, before any output to check if the user is coming from abc.php:

    if (isset($_SESSION['previous'])) {
       if (basename($_SERVER['PHP_SELF']) != $_SESSION['previous']) {
            session_destroy();
            ### or alternatively, you can use this for specific variables:
            ### unset($_SESSION['varname']);
       }
    }
    

    This way you will destroy the session (or specific variables) only if the user is coming from abc.php and the current page is a different one.

    I hope I was able to clearly explain this.

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

Sidebar

Related Questions

When I attach functionality to an element do I need to call .widgetName('destroy') before
I need to send hundreds of newsletters, but would like to check first if
I have the following restful structure: My login page uses the session/new action My
What is the difference between destroying a session and removing its values? Can you
I have an website. When the user is logged the session details will loaded.
I want to create a simple affiliate code. Currently I use PHP session to
So everything works. But if a user has firebug's console open, they'll see a
I am trying to load a html page through UIWebview.I need to disable all
i have a input tag which is non editable, but some times i need
I need to keep Security.level set on medium for Ajax reason. But I want

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.