Advertisement
Guest User

Untitled

a guest
Aug 29th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. /* Login */
  2.  
  3. <?php
  4. session_start();
  5.  
  6. include './inc/database.php';
  7.  
  8. if (!isset($_SESSION)) {
  9. session_start();
  10. }
  11.  
  12. if (isset($_SESSION['username'])) {
  13. header('Location: ./index.php');
  14. exit("Petit problème avec la redirection 'Location'");
  15. }
  16.  
  17. if(isset($_POST['username']) && isset($_POST['password'])){
  18.  
  19. $username = mysqli_real_escape_string($con, $_POST['username']);
  20. $password = mysqli_real_escape_string($con, sha1($_POST['password']));
  21.  
  22. $result = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username' && `rank` >= '1'") or die(mysqli_error($con));
  23. if(mysqli_num_rows($result) < 1){
  24. exit("Cet utilisateur n'existe pas.");
  25. }
  26. while($row = mysqli_fetch_array($result)){
  27. if($password != $row['password']){
  28. exit("Mot de passe incorrect");
  29. }else{
  30. $_SESSION['id'] = $row['id'];
  31. $_SESSION['username'] = $username;
  32. $_SESSION['email'] = $row['email'];
  33. $_SESSION['rank'] = $row['rank'];
  34. header("Location: ./index.php");
  35. }
  36. }
  37. }
  38.  
  39. ?>
  40. <!DOCTYPE html>
  41. <html>
  42. <head>
  43. <title>Connexion</title>
  44. <meta charset="utf-8">
  45. <style type="text/css">
  46. *{
  47. margin: 0px;
  48. }
  49. body{
  50. background-color: #3498DB;
  51. }
  52. #title{
  53. font-family: monospace;
  54. text-decoration: underline;
  55. }
  56. #submit_button{
  57. background-color: #52B3D9;
  58. border: 1px solid black;
  59. font-weight: bold;
  60. font-size: 15px;
  61. text-decoration: none;
  62. color: black;
  63. padding: 4px;
  64. font-family: monospace;
  65. }
  66. #login_form{
  67. border: 1px solid black;
  68. padding: 10px;
  69. padding-top: 0px;
  70. padding-bottom: 20px;
  71. width: 20%;
  72. margin: auto;
  73. text-align: center
  74. }
  75. #account_create_button{
  76. font-family: monospace;
  77. text-align: center;
  78. }
  79. </style>
  80. </head>
  81. <body>
  82. <form id="login_form" action="login.php" method="POST">
  83. <br>
  84. <h1 id="title">Connexion</h1>
  85. <br>
  86. <input type="text" id="username" name="username" placeholder="Nom d'utilisateur" required><br><br>
  87. <input type="password" id="password" name="password" placeholder="Mot de passe" required><br><br>
  88. <button id="submit_button" type="submit">Se connecter</button>
  89. </form>
  90. <div id="account_create_button">
  91. <a href="./register.php">Pas encore de compte ?</a>
  92. </div>
  93. </body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement