I am beginner and trying to learn PHP. I have made registration form where a new user can creates a new account and he/she will receive email verification link on their mail, when they click on link email will be verified. But user will not be able to login until their account gets approved by admin. And I want to show these messages as given in Example. Problem is when I reload the page it redirect to dashboard even It does not meet the if else conditions
Example : if user did not verified their email so this message should display
"You have not confirmed your account yet. Please check your inbox and verify your email"
if user account not approved by admin this message should display
"Your Account has been not approved"
if user violates the guideline (like in Facebook) and their account is disabled by admin this message should show
"Your Account has been disabled"
So this is my login script, I know am very bad in this but I am curious to know. Hope you will guide.
<?php
session_start();
if(isset($_SESSION["username"])){
header("Location:dashboard.php");
}
include("../configure/userconfig.php");
$msg='';
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
$sql010 = $conn2->prepare("SELECT * FROM register WHERE username = ? AND password = ? LIMIT 1");
$sql010->bind_param("ss",$username ,$password);
$sql010->execute();
$reS = $sql010->get_result()->fetch_all(MYSQLI_ASSOC);
if(count($reS) > 0){
$_SESSION["username"] = $reS[0]['username'];
$_SESSION["id"] = $reS[0]['id'];
$status=$reS[0]['status'];
$verification_status=$reS[0]['verification_status'];
$approval_status =$reS[0]['approval_status'];
if(!$verification_status=='1'){
$msg="<p style='display:block;'>You have not confirmed your account yet. Please check your inbox and verify your email</p>";
}else if(!$approval_status =='1'){
$msg="<p style='display:block;'>Your Account has been not approved</p>";
}else if (!$status=='1'){
$msg="<p style='display:block;'>Your Account has been disabled</p>";
}else{
header("Location:dashboard.php");
}
}else{
$msg="<p style='display:block;'>Invalid username and password</p>";
}
}
Aucun commentaire:
Enregistrer un commentaire