Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if( isset($_SESSION['user_id']) ){
  4. header("Location: /");
  5. }
  6. require 'database.php';
  7. if (!empty($_POST['username']) && !empty($_POST['password'])):
  8. $records=$conn->prepare('select id, username, password from admin where username = :username');
  9. $records->bindParam(':username', $_POST['username']);
  10. $records->execute();
  11. $results=$records->fetch(PDO::FETCH_ASSOC);
  12. $message='';
  13.  
  14. if(count($results)>0 && password_verify($_POST['password'], $results['password'])){
  15. $_SESSION['user_id']=$results['id'];
  16. header("Location: /");
  17. }else{
  18. echo 'Sorry, wrong password';
  19. }
  20. endif;
  21. ?>
  22. <html>
  23. <head>
  24. <link href='http://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet' type='text/css'>
  25. <title>Admin Login</title>
  26. </head>
  27. <body>
  28. <?php if(!empty($message)): ?>
  29. <p><?=$message ?></p>
  30. <?php endif; ?>
  31. <h1>Admin Login</h1>
  32. <form id='login' method='POST' action='login.php'>
  33. <label>
  34. Username:
  35. <input type='text' name='username' placeholder='Enter your usename' id='username' size='20' maxlength='100'>
  36. </label>
  37. <br>
  38. <label>
  39. Password:
  40. <input type='text' name='username' placeholder='Enter your password' id='username' size='20' maxlength='100' >
  41. </label>
  42. <br>
  43.  
  44. <button type='button'>Login</button>
  45. </form>
  46. <a href="register.php">Register</a>
  47. <br/>
  48. <style type='text/css'>
  49. form{
  50. font-family: Verdana;
  51. width: auto;
  52. text-align: center;
  53. }
  54. label {
  55. width: 150px;
  56. font-size: 170%;
  57. length: 200px;
  58. }
  59. body{
  60. background-color: lightblue;
  61. text-align: center;
  62. position: fixed;
  63. top: 50%;
  64. left: 50%;
  65. margin-top: -100px;
  66. margin-left: -200px;
  67. height:200px;
  68. width:400px;
  69. }
  70.  
  71. button{
  72. padding:10px;
  73. color:#fff;
  74. background:#0098cb;
  75. width:200px;
  76. margin:20px auto;
  77. margin-top:0px;
  78. border:0px;
  79. border-radius: 3px;
  80. cursor:pointer;
  81.  
  82. }
  83. input[type='text']{
  84. height:30px;
  85. outline:none;
  86. padding:10px;
  87. width:200px;
  88. border-radius: 3px;
  89. border:1px solid #eee;
  90. margin:20px auto;
  91. }
  92. button:hover{
  93. background:#00b8eb;
  94. }
  95.  
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement