<?php session_start();
if(isset($_SESSION[‘valid’])){
echo “<script> location=’Welcome.php’ </script>”;}
else session_destroy();
if(isset($_POST[‘sub’]))
{
$uname=$_POST[‘uname’];
$pwd=$_POST[‘pwd’];
if($uname==”Webnoid” and $pwd= “School”)
{
session_start();
$_SESSION[‘valid’]=true;
$_SESSION[‘uname’]=$uname;
echo “<script> location=’Welcome.php'</script>”;
}
else{
echo “Invalid”;
}
?>
<form method=”post” action=” “>
username: <input type=”text name=”uname”>
password: <input type=”password” name=”pwd”>
<input type=”submit” value=”login” name= “sub
</form>
Welcome.php
<?php
session_start();
if(isset($_SESSION[‘valid’]))
{
echo “Welcome to user”;
echo #_SESSION[‘uname];
}
else{
echo “<script> location=’login.php'</script>”;
?>
<a href= ‘logout.php> logout </a>
logout.php
<?php
session_start();
session_destroy();
echo “Logged out successfully”;
?>