title: How to store session in when click button start to again click button end time for calculate start to end time in php
body: <p>I want to chart for daily spending hours in browser. In the chart each day spending hours are mentioned. When I click the button time will start and again click the button time will end and finally calculate start to end time stored in like session or any other. This will happen for three days and finally chart will generate.</p>
  
  <p>HTML CODE:</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
          &lt;form action="time_calculation.php" method="POST"&gt;
              &lt;input type="submit" name="start" value="Start"&gt;
              &lt;br&gt;&lt;br&gt;
              &lt;input type="submit" name="end" value="End"&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>php:</p>
  
  <pre><code>&lt;?php
  session_start();
  if(isset($_POST['start'])) {
      date_default_timezone_set('Asia/Calcutta'); 
      $time_start=date("Y-m-d h:i:s A"); 
      $_SESSION['start']='$time_start';
      echo "time start now ".$time_start."&lt;br&gt;";
  }
  
  if(isset($_POST['end'])) {
      date_default_timezone_set('Asia/Calcutta'); 
      $time_end=date("Y-m-d h:i:s A"); 
      $_SESSION['end']='$time_end';
      echo "time was ended".$time_end."&lt;br&gt;"; 
      $sst=strtotime($_SESSION['start']);
      $eet=strtotime($_SESSION['end']);
      $diff=$eet-$sst;
      $timeelapsed=mktime("h:i",$diff);
      echo $timeelapsed;
  }
  ?&gt;
  </code></pre>