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 6783675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:53:44+00:00 2026-05-26T16:53:44+00:00

Is it possible to run a function when the session ends on a PHP

  • 0

Is it possible to run a function when the session ends on a PHP script? My script asks several questions and the user has 30 minutes to answer or the session expires. I would like my script to save any progress to a .txt file if the session expires and the user has not completed all the answers. How would I go about doing this?

I heard about register_shutdown_function(‘shutdown’); but I’m confused on where I would call it in my script.

My current script starts like this:

 ini_set('session.gc_maxlifetime',1800);
 ini_set('session.gc_probability',1);
 ini_set('session.gc_divisor',1);
 session_start();
 if($_SESSION['loggedin'] !== 1) {//checks to see if user has logged in
 header('Location: login.php');
 exit;}

 ...asks a bunch of questions....
 session_destroy();

Thanks for your help.

  • 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-26T16:53:45+00:00Added an answer on May 26, 2026 at 4:53 pm

    You have actually two options:

    1. Save the progress when it happens (after every answer) and save information whether it has been completed. This solution works even if the browser has been closed (the progress is saved in real time).

    2. Use AJAX to call the server every eg. 5 seconds and server should return information whether the session ended or not. If session ended, then do in JS what you need (even redirect to different page). This solution does not ensure saving the progress (the browser may be closed before action is made).

    You can combine both options, depending on what you need and how your application works.

    If page reloads after every answer (eg. reloads to show next question), then you can use option no. 1. If all the questions are on one page, choose option no. 2. If your application is combination of the two, you can choose both options.

    EDIT:

    Judging from your code, you are mixing:

    • session in terms of the time for answering questions with
    • session in terms of storing values between requests to the page in PHP.

    The best idea is to separate the two. Give PHP session a much larger time limit, because it is needed for some other things such as actually showing progress or even saving progress. Instead, mark the time when the test began and store it in PHP session. This way after the time for the test is exhausted, you will be able to determine that and ignore any questions answered after that.

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

Sidebar

Related Questions

is it possible to run a sub or function as soon as the user
Is it possible to run both debuggers within the same PHP installation simultaneously. They
Is it possible to run a windows xp bat script remotely from a ubuntu
It is possible to run the urlencode function without converting # or % ?
Is it entire possible to run Facebook SDK code integrated into a jQuery script?
Is it possible to run a function when referring to a variable in a
How it is possible to call a function from a other PowerShell script an
Is it possible to run javascript code within a php loop? the javascript works
I'm creating a memory game that should be possible to run as several games
I'm reusing an old application (a game) so it's possible to run several games

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.