<?php
session_start();
error_reporting(0);
function show_login_success(){
echo "Login Success..!";
echo "<a href='?logout'>Click here to logout</a>";
}
function show_login_form(){
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']?>">
<input name="txtUserName" placeholder="Enter username">
<input type="password" name="txtPassword" placeholder="Enter Password"/>
<input type="submit" name="btnLogin"/>
</form>
<?php }
function show_logout(){
echo 'Logout Success..<a href="'.$_SERVER['PHP_SELF'].'">Click to Login</a>';
session_destroy();
}?>
<?php
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']=="logout"){
show_logout();
}else if(isset($_POST['btnLogin'])){
if($_REQUEST['txtUserName']=="Sujith" && $_REQUEST['txtPassword']=="Sujith123"){
$_SESSION['logged']=TRUE;
show_login_success();
}else { echo "Invalid Username or Password.<br/>"; show_login_form();}
}else if($_SESSION['logged']){ show_login_success();} else { show_login_form();?>
<?php } ?>
session_start();
error_reporting(0);
function show_login_success(){
echo "Login Success..!";
echo "<a href='?logout'>Click here to logout</a>";
}
function show_login_form(){
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']?>">
<input name="txtUserName" placeholder="Enter username">
<input type="password" name="txtPassword" placeholder="Enter Password"/>
<input type="submit" name="btnLogin"/>
</form>
<?php }
function show_logout(){
echo 'Logout Success..<a href="'.$_SERVER['PHP_SELF'].'">Click to Login</a>';
session_destroy();
}?>
<?php
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']=="logout"){
show_logout();
}else if(isset($_POST['btnLogin'])){
if($_REQUEST['txtUserName']=="Sujith" && $_REQUEST['txtPassword']=="Sujith123"){
$_SESSION['logged']=TRUE;
show_login_success();
}else { echo "Invalid Username or Password.<br/>"; show_login_form();}
}else if($_SESSION['logged']){ show_login_success();} else { show_login_form();?>
<?php } ?>
0 comments:
Post a Comment