Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "inc/header.php";
- include "inc/functions.php";
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- if(isset($_POST["admin_login"])) {
- $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
- $password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
- $admin = get_admin_login($username, $password);
- if(! session_id()){
- session_start();
- }
- if(! empty($admin)) {
- if($admin['username'] == $username) {
- if($admin['password'] == $password) {
- $_SESSION['msg'] = "Welcome Again " . $username;
- redirect("index.php");
- }else {
- $_SESSION['error_msg'] = "Wrong Password";
- redirect("login.php");
- }
- }else {
- $_SESSION['error_msg'] = "Wrong Username";
- redirect("login.php");
- }
- }else {
- $_SESSION['error_msg'] = "Wrong Login, Check your Username and Password";
- redirect("login.php");
- }
- }
- }
- ?>
- <div class="login-alerts">
- <?php if(! session_id()) {
- session_start();
- }
- if(! empty($_SESSION['error_msg'])) {
- echo "<div class='alert alert-danger'>";
- echo $_SESSION['error_msg'];
- echo "</div>";
- $_SESSION['error_msg'] = "";
- }
- if(! empty($_SESSION['msg'])) {
- echo "<div class='alert alert-success'>";
- echo $_SESSION['msg'];
- echo "</div>";
- $_SESSION['msg'] = "";
- }
- ?>
- </div>
- <div class="form">
- <div class="form-header">
- <h3 class="text-center">Welcome to <span style="color: #b30b0b">Z</span>Blog</h3>
- </div>
- <div class="form-body">
- <form class="form" action="login.php" method="POST" >
- <div class="form-group">
- <span class=""></span>
- <input type="text" name="username" class="form-control" placeholder="Username" required autocomplete="off" >
- </div>
- <div class="form-group">
- <span class=""></span>
- <input type="password" name="password" class="form-control" placeholder="Password" required autocomplete="off">
- </div>
- <div class="form-group">
- <input style="float: right;" type="submit" name="admin_login" class="btn btn-default" value="Login" >
- <a href="" style="float: left;">Forgot your password?</a>
- </div>
- </form>
- </div>
- </div>
- <?php include "inc/footer.php"; ?>
- function get_admin_login($username, $password) {
- include "connect.php";
- $sql = "SELECT id, username, password FROM admins WHERE username = ? && password = ? ";
- try {
- $result = $con->prepare($sql);
- $result->bindValue(1,$username, PDO::PARAM_STR);
- $result->bindValue(2,$password, PDO::PARAM_STR);
- $result->execute();
- return $result->fetchAll(PDO::FETCH_ASSOC);
- }catch(Exception $e) {
- echo "Error: ". $e->getMessage(). "n";
- return false;
- }
Add Comment
Please, Sign In to add comment