Advertisement
jimmyfeu

Untitled

Nov 16th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset = "utf-8">
  5.         <title>Login</title>
  6.         <link rel="stylesheet" href="../TP 1/css/style.css"/>
  7.     </head>
  8.    
  9. <body>
  10.     <?php
  11.         include('../TP Djamil Stasaid/db.php');
  12.         session_start();
  13.    
  14.         // if form submitted, insert values into the database.
  15.     if (isset($_POST['username'])){
  16.         $username = stripslashes($_REQUEST['username']); //removes backslashes + security
  17.         $username = mysqli_real_escape_string($conn,$username); //escapes special characters in a string + security
  18.         $password = stripslashes($_REQUEST['password']);
  19.         $password = mysqli_real_escape_string($conn,$password);
  20.        
  21.     //Checking if user existing in the database or not
  22.     $query = "SELECT * FROM users WHERE username='$username' and password='".$password."'";
  23.     $result = mysqli_query($conn,$query) or die(mysql_error());
  24.        
  25.     $rows = mysqli_num_rows($result);
  26.     print_r ($rows);
  27.         if($rows==1){
  28.             $_SESSION['username'] = $username;
  29.             header("Location: imc.php"); //redirect user to imc.php
  30.         }else {
  31.             echo "<div class='form'><h3>Username/password is incorrect.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
  32.             }
  33.         }else {
  34.     ?>
  35.     <div class="form">
  36.         <h1>Log In</h1>
  37.             <form action="login.php" method="post" name="login">
  38.                 <input type="text" name="username" placeholder="Username" required/>
  39.                 <input type="password" name="password" placeholder="Password" required/>
  40.                 <input name="submit" type="submit" value="Login"/>
  41.             </form>
  42.         <p>Not registred yet? <a href='../TP 1/registration.php'>Register Here</a></p>
  43.             <br/><br/>
  44.     </div>
  45.    
  46.     <?php } ?> 
  47. </body>
  48.  
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement