Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Login */
- <?php
- session_start();
- include './inc/database.php';
- if (!isset($_SESSION)) {
- session_start();
- }
- if (isset($_SESSION['username'])) {
- header('Location: ./index.php');
- exit("Petit problème avec la redirection 'Location'");
- }
- if(isset($_POST['username']) && isset($_POST['password'])){
- $username = mysqli_real_escape_string($con, $_POST['username']);
- $password = mysqli_real_escape_string($con, sha1($_POST['password']));
- $result = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username' && `rank` >= '1'") or die(mysqli_error($con));
- if(mysqli_num_rows($result) < 1){
- exit("Cet utilisateur n'existe pas.");
- }
- while($row = mysqli_fetch_array($result)){
- if($password != $row['password']){
- exit("Mot de passe incorrect");
- }else{
- $_SESSION['id'] = $row['id'];
- $_SESSION['username'] = $username;
- $_SESSION['email'] = $row['email'];
- $_SESSION['rank'] = $row['rank'];
- header("Location: ./index.php");
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Connexion</title>
- <meta charset="utf-8">
- <style type="text/css">
- *{
- margin: 0px;
- }
- body{
- background-color: #3498DB;
- }
- #title{
- font-family: monospace;
- text-decoration: underline;
- }
- #submit_button{
- background-color: #52B3D9;
- border: 1px solid black;
- font-weight: bold;
- font-size: 15px;
- text-decoration: none;
- color: black;
- padding: 4px;
- font-family: monospace;
- }
- #login_form{
- border: 1px solid black;
- padding: 10px;
- padding-top: 0px;
- padding-bottom: 20px;
- width: 20%;
- margin: auto;
- text-align: center
- }
- #account_create_button{
- font-family: monospace;
- text-align: center;
- }
- </style>
- </head>
- <body>
- <form id="login_form" action="login.php" method="POST">
- <br>
- <h1 id="title">Connexion</h1>
- <br>
- <input type="text" id="username" name="username" placeholder="Nom d'utilisateur" required><br><br>
- <input type="password" id="password" name="password" placeholder="Mot de passe" required><br><br>
- <button id="submit_button" type="submit">Se connecter</button>
- </form>
- <div id="account_create_button">
- <a href="./register.php">Pas encore de compte ?</a>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement