Guest User

Untitled

a guest
Jan 19th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. <?php
  2. include "inc/header.php";
  3. include "inc/functions.php";
  4.  
  5. if($_SERVER['REQUEST_METHOD'] == 'POST') {
  6. if(isset($_POST["admin_login"])) {
  7.  
  8. $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
  9. $password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
  10.  
  11. $admin = get_admin_login($username, $password);
  12.  
  13. if(! session_id()){
  14. session_start();
  15. }
  16. if(! empty($admin)) {
  17. if($admin['username'] == $username) {
  18. if($admin['password'] == $password) {
  19. $_SESSION['msg'] = "Welcome Again " . $username;
  20. redirect("index.php");
  21. }else {
  22. $_SESSION['error_msg'] = "Wrong Password";
  23. redirect("login.php");
  24. }
  25. }else {
  26. $_SESSION['error_msg'] = "Wrong Username";
  27. redirect("login.php");
  28. }
  29. }else {
  30. $_SESSION['error_msg'] = "Wrong Login, Check your Username and Password";
  31. redirect("login.php");
  32. }
  33. }
  34. }
  35. ?>
  36.  
  37.  
  38. <div class="login-alerts">
  39. <?php if(! session_id()) {
  40. session_start();
  41. }
  42. if(! empty($_SESSION['error_msg'])) {
  43. echo "<div class='alert alert-danger'>";
  44. echo $_SESSION['error_msg'];
  45. echo "</div>";
  46. $_SESSION['error_msg'] = "";
  47. }
  48. if(! empty($_SESSION['msg'])) {
  49. echo "<div class='alert alert-success'>";
  50. echo $_SESSION['msg'];
  51. echo "</div>";
  52. $_SESSION['msg'] = "";
  53. }
  54. ?>
  55. </div>
  56. <div class="form">
  57. <div class="form-header">
  58. <h3 class="text-center">Welcome to <span style="color: #b30b0b">Z</span>Blog</h3>
  59. </div>
  60. <div class="form-body">
  61. <form class="form" action="login.php" method="POST" >
  62. <div class="form-group">
  63. <span class=""></span>
  64. <input type="text" name="username" class="form-control" placeholder="Username" required autocomplete="off" >
  65. </div>
  66. <div class="form-group">
  67. <span class=""></span>
  68. <input type="password" name="password" class="form-control" placeholder="Password" required autocomplete="off">
  69. </div>
  70. <div class="form-group">
  71. <input style="float: right;" type="submit" name="admin_login" class="btn btn-default" value="Login" >
  72. <a href="" style="float: left;">Forgot your password?</a>
  73. </div>
  74. </form>
  75. </div>
  76.  
  77. </div>
  78.  
  79. <?php include "inc/footer.php"; ?>
  80.  
  81. function get_admin_login($username, $password) {
  82. include "connect.php";
  83. $sql = "SELECT id, username, password FROM admins WHERE username = ? && password = ? ";
  84. try {
  85. $result = $con->prepare($sql);
  86. $result->bindValue(1,$username, PDO::PARAM_STR);
  87. $result->bindValue(2,$password, PDO::PARAM_STR);
  88.  
  89. $result->execute();
  90. return $result->fetchAll(PDO::FETCH_ASSOC);
  91. }catch(Exception $e) {
  92. echo "Error: ". $e->getMessage(). "n";
  93. return false;
  94. }
Add Comment
Please, Sign In to add comment