Session variable of N-1 instead of N
<p>I have a timer in jquery and i would like to keep the value when i refresh the page. I am using php session variable with some ajax. But when i refresh it keeps the value of N-1 instead of N.</p>

<p>Example : </p>

<p>I am at 20 second when i refresh nothing happens. Then when i refresh back at 18 seconds it is the 20 seconds who outputs </p>

<p>Here is the code : </p>

<pre><code>&lt;?php
session_start();
if (isset($_GET['number'])) {
$_SESSION['timer']=$_GET['number'];
}
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;


 &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"&gt;&lt;/script&gt;
  &lt;script src="cookie.js"&gt;&lt;/script&gt;

        &lt;script&gt;

$(window).unload(function() {

var number = $('#test').text();
alert(number);
          $.get('divb.php',{number:number},function(resultat){
                        return false;                                                       
                });



});         


$(document).ready(function(){


var numb = 30 ;                 
var numba = 100 ; 

function comptage() {

setTimeout(comptage,1000);
$('#test').html(numb);
$("#progressbar").progressbar({ value: numba });

numb -- ;
numba = numba - (numba/numb) ;


if (numb &lt; 0 )
{

numb = 0 ; 
numba = 0 ;
}



};

comptage();












    });     







            &lt;/script&gt;   


&lt;style &gt;

#affichage_point

{
position:relative;
    background-color:  #FFFFFF;
 border: 1px solid  #7375D8;
width:450px ; 
height:5px ; 
    margin-left: 200px;
    margin-top: 100px;

   padding:30px;

}

   #progressbar  {

  width : 400px ;

  }


  #progressbar &gt; div {

  background: #7375D8;

  }


#bardivs {
    width:400px; 
     position:absolute;
      top:12px;
      left: 50px;


     }

#test {
    position:absolute;
    top:5px;
    left:5px;
}



&lt;/style&gt;






   &lt;/head&gt;


    &lt;body&gt;


    &lt;div id = "affichage_point"&gt;
    &lt;div id="bardivs"&gt;
    &lt;div id="progressbar"&gt;&lt;/div&gt;
    &lt;div id="test"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;


&lt;?php   if (isset($_SESSION['timer'])) { ?&gt;
     &lt;div id ="r6"&gt;&lt;?php echo $_SESSION['timer'] ?&gt; &lt;/div&gt; &lt;br/&gt; 
     &lt;?php } ?&gt;


        &lt;/body&gt;
&lt;/html&gt;
</code></pre>
