BruceFelix / Ecycle-room-5-project

0 stars 0 forks source link

Making admin go to admin page #14

Open paminus-kingori opened 3 years ago

paminus-kingori commented 3 years ago

Making admin go to admin page.

paminus-kingori commented 3 years ago

<?php //create db connection session_start(); require 'connection.php'; if(!isset($_SESSION['errorNumber'])){ $_SESSION['errorNumber'] = 0; } if(!isset($_SESSION['attempts'])){ $_SESSION['attempts'] = 0; }

if(isset($_POST['username']) && isset($_POST['password'])){

$username = mysqli_escape_string($connection,$_POST['username']); $pass = mysqli_escape_string($connection,$_POST['password']);

//the username entered should match with the password $selectUser = "SELECT * FROM userdetails WHERE username='$username' "; $received = mysqli_query($connection,$selectUser);

//checking number of rows received if(!$received){ echo "msqli error" .mysqli_error($connection); } else{ $row =mysqli_num_rows($received); $received = mysqli_fetch_assoc($received); if($row>0) {

    if($_SESSION['attempts']<3){
            if(password_verify($pass,$received['password']))
            {

                $_SESSION['username'] = $username;
                echo $_SESSION['username'] ."welcome";
               //delay the code below for 5 seconds
                // sleep(5);
                header("location: ../front-end/landing-shop/landing.php");

            }
            else{
                $_SESSION['errorNumber'] = 1;
               $checkPassword = "<div style = 'color:red'> <strong>Check Your password </strong></div>";

                $_SESSION['attempts']++;

                // header("location: ../front-end/login-page/login.html");

                $attemptsLeft = "<div style = 'color:red'> <strong>You have " .(3-$_SESSION['attempts']) ." attempts left. </strong></div>";
                // sleep(5);
                header("location:../front-end/login-page/loginNew.php");

            }
        }
    else{
        $_SESSION['errorNumber'] = 2;
        $endOfAttempts = "<div style = 'color:red'> <strong>You can only make 3 attempts at a login. <br> Please wait 10 mins before trying again. </strong></div>";
        // sleep(5);
        // header("location:../front-end/login.html");
        header("location:../front-end/login-page/loginNew.php");

    }

    }
else
     {
        $_SESSION['errorNumber'] = 3;
         $noUser = "<h1 style= 'color:red; text-transform: uppercase;'>User not registered</h1> <br> ";

        echo  $_SESSION['attempts'];
        header("location:../front-end/login-page/loginNew.php");

        }
                }

}

// //Check to see if our countdown session // //variable has been initialized. // if(!isset($_SESSION['countdown'])){ // //Set the countdown to 120 seconds. // $_SESSION['countdown'] = 120; // //Store the timestamp of when the countdown began. // $_SESSION['time_started'] = time(); // }

// //Get the current timestamp. // $now = time();

// //Calculate how many seconds have passed since // //the countdown began. // $timeSince = $now - $_SESSION['time_started'];

// //How many seconds are remaining? // $remainingSeconds = abs($_SESSION['countdown'] - $timeSince);

// //Print out the countdown. // // echo "There are $remainingSeconds seconds remaining.";

// //Check if the countdown has finished. // if($remainingSeconds < 1){ // //Finished! Do something. // // echo "

It is done

"; // }

?>