php session tutorial with examples

Example 1: php delete session

session_destroy(); // To delete whole session
// OR
unset($_SESSION['myVar']); // To delete a session var

Example 2: session start php

<?php
// This sends a persistent cookie that lasts a day.
session_start([
    'cookie_lifetime' => 86400,
]);
?>

Example 3: can we acces session variable in two files

<?php
  session_start();

  ...

  if($responseCode == 1) {
    $_SESSION['card_id']    = $_POST['card_id'];
    $_SESSION['password']   = $_POST['password'];
    print '<script type="text/javascript">'; 
    print 'window.location = "http://domain.com/File2.php";';
    print '</script>';
  }
?>