There is a login page called login.php, after user type their username and password into textbox, then the page direct it to the page validate, which is validate.php. In validate.php, if user do not type anything, then direct it to the login.php again; if user type their username and password worng less than 3 times, then direct it to the login.php also. However, if user type their username and password more than 3 times, then direct it to the register.php.
Question: i don't know how to make 3 attempts (maybe there are something worng in my page), it doesn't work, Please help, here is my validate.php
<?php
$loginErrorV = false;
$loginErrorW = false;
if(!empty($_POST['username']) && !empty($_POST['password']) && strlen($_POST['username'])!=0 && strlen($_POST['password'])!=0)
{
//
$username = $_POST['username'];
$password = $_POST['username'];
//Connect to Database
$conn = mysql_connect("localhost", "root", "");
if(!$conn){
die('Could not connect:'.mysql_error());
}
mysql_select_db("logindb", $conn);
//
$sql = "Select count(username) as user_exist from logint where username = '$username' and password = '$password'";
$result = mysql_query($sql, $conn);
$row = mysql_fetch_assoc($result);
//
if($row['user_exist'] == 1){
session_start();
$_SESSION['username'] = $username;
header('Location: 10586740.html');
mysql_close($conn);
} else {
$loginErrorV = true;
}
} else {
$loginErrorW = true;
}
if($loginErrorV){
if(isset($_COOKIE['login'])){
if($_COOKIE['login']<3){
header('Location:login.php');
$attempts = $_COOKIE['login'] + 1;
} else {
header('Location:register.php');
}
}
}
if($loginErrorW){
header('Location:login.php');
}
?>