如何结束php会话并在用户选择操作时开始新的会话

This relates to my question here, which had to do with making variables usable in multiple php files. Both Ian Hildebrand and Transcendental offered useful advice.

I want to let a user select, say, 6 a.m. from a form and view data pertaining to that hour, in either or both of two views, View_A and View_B. If the user then wants to look at data from 7 a.m. then he/she just reloads the form and selects that hour and submits.

What happens now is that the variable $hour stays stuck at 6 a.m. So the user can select whatever hour he/she wishes but still gets 6 a.m. data.

So what I want is, when the user selects the new hour, that action ends the first session and starts a new one.

here's the applicable code from the form file:

   <form action='view_A.php' method='post'>
        <label for 'date'><strong>Select an hour for <?php echo $date; ?></strong>
        </label>
        <input type="text" name='hour' data-role="datebox" data-options='{"mode":"timeflipbox","minuteStep":60, "overrideTimeFormat": "%H", "overrideTimeOutput": "%H"}' placeholder='click icon to select hour'>
        <input type='submit' name='submit' value='submit'>
    </form>
    </div>
<?php
if(isset($_POST[ 'submit'])) { 
$_SESSION[ 'hour']=$ _POST[ 'hour']; 
$hour=$ _SESSION[ 'hour']; }
?>

... and applicable code in the file view_A.php

session_start();
error_reporting(E_ALL);
include ("db_connect.php");
date_default_timezone_set('America/Toronto');
$date = date('Y-m-d');
$hour =     $_SESSION['hour'];
$blink = $_SESSION['hour'];
$date_hour = $date.' '.$hour;

Both these files lead off with session_start(); right after the opening php tag.

How could I modify the form file so that when the user selects a new hour the current session ends and a new one starts?

You never get to to the if(isset()) part of the code. As action the form will direct the user directly to Vieuw_A.php

You have to put it in View_A.php

session_start();
error_reporting(E_ALL);
include ("db_connect.php");
date_default_timezone_set('America/Toronto');

$_SESSION['hour'] = $_POST['hour'];

$date = date('Y-m-d');
$hour = $_SESSION['hour'];
$blink = $_SESSION['hour'];
$date_hour = $date.' '.$hour;

although you could skip the session all together

session_start();
error_reporting(E_ALL);
include ("db_connect.php");
date_default_timezone_set('America/Toronto');

$date = date('Y-m-d');
$hour = $_POST['hour'];
$blink = $_POST['hour'];
$date_hour = $date.' '.$hour;

I hope this fixed your problem