index.php
<?php session_start();?>
<?php
if(isset($_POST['sub'])){
if($_POST['username'] =="manikanta" && $_POST['password']=="mani123"){
$_SESSION['login'] = true;
print_r($_SESSION);
$_SESSION['name']=$_POST['username'];
}
else{
echo "Login fail";
}
}
if(isset($_SESSION['login'])){
if($_SESSION['login']){
echo "<script>location.href='welcome.php'</script>";
}
}
?>
<html>
<head>
</head>
<body>
<form action="" method="post">
<input type="text" name="username" value="<?php echo isset($_POST['username']) ? $_POST['username'] : '' ?>"/>
<input type="password" name="password" />
<input type="submit" name="sub" value="submit"/>
</form>
</body>
</html>
welcome.php
<?php session_start();
if(isset($_SESSION['login'])){
if(!$_SESSION['login']){
echo "<script>location.href='index.php'</script>";
}
}
?>
Welcome <?php echo isset($_SESSION['name']) ? $_SESSION['name'] : '' ; ?> <a href="logout.php">Logout</a>
logout.php
<?php session_start();
if(isset($_SESSION['login'])){
if($_SESSION['login']){
session_destroy();
echo "<script>location.href='index.php'</script>";
}
echo "<script>location.href='index.php'</script>";
}else
?>
0 comments:
Post a Comment