title: How to update the PHP current timestamp using jquery/javascript every second
body: <p>I am working on the PHP cart timer script using PHP and jQuery/JavaScript. </p>
  
  <p>I am iterating the set-interval function every seconds to get the PHP's current time-stamp.</p>
  
  <p>When the first product is added to the cart, the timer begins before getting timer-stops it prompts the user, whether the user want to continue or cancel. </p>
  
  <p>My code is follows    </p>
  
  <pre><code>$(document).ready(function(){
      var orderedtime = "echo $_SESSION['ordertime'];";
      if (orderedtime === null || orderedtime == ''){
         console.log("orderedtime is not set");
      }
      else{
         init();
     }
  });
  var currenttime;
  var alerttime;
  var extratime;
  function cd(){
      alerttime = "&lt;?php echo date('h:i:s', (strtotime($_SESSION['ordertime']) + (1 * 60)));  ?&gt;"
      extratime = "&lt;?php echo date('h:i:s', (strtotime($_SESSION['ordertime']) + (2 * 60)));  ?&gt;";
      redo();
  }
  function redo(){
      currenttime = "&lt;?php echo date('h:i:s', time()); ?&gt;";
      if(alerttime == currenttime) {
          //doing something   
      }
      else if(currenttime == extratime){
          //doing something
      }
      else{
          cd = setTimeout("redo()",1000);
      }
  }
  function init(){
      cd();
  }
  </code></pre>
  
  <p>The currenttime variable only storing the 1st iteration value is not getting updating.</p>
  
  <p>How to solve this issue?</p>
  
  <p>Please kindly help me to solve it.</p>
  
  <p>Thanks in advance.  </p>