Run a function when session expires?
<p>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 <strong>if the session expires</strong> and the user has not completed all the answers.  How would I go about doing this?</p>

<p>I heard about register_shutdown_function('shutdown'); but I'm confused on where I would call it in my script.  </p>

<p>My current script starts like this:</p>

<pre><code> 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();
</code></pre>

<p>Thanks for your help.  </p>
