index.php
<?php
error_reporting(1);
session_start();
if(isset($_POST['sub'])){
$name=$_POST['name'];
$pass=$_POST['pass'];
if($name=="mr.mahajan@hotmail.com" && $pass=="aks123"){
$_SESSION['akshay']=$name;
$_SESSION['start']=time();
$_SESSION['expire']=$_SESSION['start'] + (1*60);
header('location:Homepage.php');
}else{
$err="<font color='red' size='7'>Invalid user login</font>";
}
}
?>
<html>
<head>
<title>Session After 5 minute</title>
</head>
<body>
<form name="form1" method="post">
<tr>
<td colspan="2">
<?php echo $err; ?>
</td>
</tr>
<tr>
<td>Name:</td>
<td>
<input type="text" name="name" autofocus>
</td>
</tr>
<td>Pass:</td>
<td>
<input type="password" name="pass">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="sub" value="submit">
</td>
</tr>
</form>
</body>
</html>
HomePage.php
<?php
session_start();
if(isset($_SESSION['akshay'])){
echo "<a href='index.php' name='index'>Click Here to Login</a>";
}else{
$now=time();
if($now > $_SESSION['expire']){
session_destroy();
//echo '<a href="index.php" name="index">Click to Login</a>';
header('location:index.php');
}
}
?>
<html>
<head>
<title>Homepage</title>
</head>
<body>
<p style="background:#09C">
welcome <?php echo $_SESSION['akshay']; ?>
<span style="float:right"><a href='logout.php'>LogOut</a></span>
<p style="padding-top:20px;background:#CCCCCC; height:400px; text-align:center">
<span style="color:red;text-align:center">Your Session Will destroy after 1 minutes You will redirected on next page</span>
<br/><br/>
<span>if you want to logout before 1 minute click on logout link </span>
</p>
</p>
</p>
</body>
</html>
logout.php
<?php
session_start();
session_destroy();
header('location:index.php');
?>