<?php

//Set the session timeout for 2 hours
$timeout = 7200;
//Set the maxlifetime of the session
ini_set( "session.gc_maxlifetime", $timeout );
//Set the cookie lifetime of the session
ini_set( "session.cookie_lifetime", $timeout );

//Start a new session
session_start();
//Set the default session name
$s_name = session_name();

date_default_timezone_set('America/Toronto');
$wantedTime = strtotime("now")."<br/>";
echo date("Y-m-d H:i:s", $wantedTime)."<br>";

//Check the session exists or not
if(isset( $_COOKIE[ $s_name ] )) {

    setcookie( $s_name, $_COOKIE[ $s_name ], time() + $timeout, '/' );
    echo "Session is created for $s_name.<br/>";
}
else
    echo "Session is expired.<br/>";
    
?>