I am new to PHP. So I made a loginform for my website and where I'm having trouble hiding the form after the user logs in.. I want it to disappear after the user sucessfully logs in. My code is the following,
<?php
include "connect.php";
$_SESSION['backurl'] = basename($_SERVER['PHP_SELF']);
?>
<div class = "loginform">
<form name = "login" action = "login.php" method = "post" accept-charset = "utf-8">
<?php
echo $_SESSION['username'];
//IF LOGADO TIRAR FORM.
?>
<ul>
<li><label for = "usermail" class = "letralogin" >Email</label>
<input type = "email" name = "usermail" placeholder = "yourname@email.com" required></li>
<p>
<li><label for = "password" class = "letralogin">Password</label>
<input type = "password" name = "password" placeholder = "password" required></li>
<p>
<input type = "submit" name = "login" value = "Login"></li>
</ul>
</form>
</div>
<div class = "divreg">
<input type = "button" onclick = "location.href = 'registo.php';" value = "Registo" class = "buttreg"/>
</div>
This is my code on login.php,
<?php
include "connect.php";
if(isset($_POST['login']))
{
$username = $_POST['usermail'];
$password = sha1($_POST['password']);
$sql = "select * from utilizador where email = '$username' and password = '$password'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
echo 'OK';
$_SESSION['username'] = $username;
header('Location: ' . $_SESSION['backurl']);
}
else
{
echo 'wrong password';
header('Location: ' . $_SESSION['backurl']);
}
}
else
{
header('Location: inicio.php');
}
?>