basic level login and logout

basic level login and logout

basic level login and logout



when we talk about login and logout in php, there are some checks must be done for further tasks:

check the person who accessed the admin page must be filled the input fields like email and password before accessing the admin page
there must be a logout button for exiting account

login.php:


<?php
if(isset($_POST['save']))
{
echo"hello";

session_start();
$_SESSION['email']=$_POST['useremail'];
$_SESSION['pass']=$_POST['userpass'];

header('Location:admin.php');


}
?>
<html>
<head>

</head>
<body>
<form method="post">

<div>
<div><label>email</label></div>

<input type="email" name="useremail" required>
</div>


<div>
<div><label>password</label></div>

<input type="password" name="userpass" required>
</div>

<div><input type="submit" value="login" name="save"></div>

</form>
</body>
</html>


admin.php

after login, admin.php is a file that is accessed after login.




<?php
session_start();



if(isset($_SESSION['email'] ) && isset($_SESSION['pass'] ))
{

echo $_SESSION['email'];

echo $_SESSION['pass'];
}
else
{
session_unset();
session_destroy();
header('Location:login.php');

}










#unset the session value: session_unset();


#end the session:sessionn_destroy();


#move to the login page after logout:header('Location:login.php');










if(isset($_POST['logout']))
{
session_unset();
session_destroy();
header('Location:login.php');
}
?>
<html>
<head>

</head>
<body>
<form method="post">
<input type="submit" value="logout" name="logout">
</form>
</body>
</html>

0 Comments