Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <?php
  2. require_once('functions.php');
  3. dbConnect('localhost', 'root', '', 'website');
  4. session_start();
  5.  
  6. if(isset($_POST['login'])){
  7.     if(isset($_POST['username'], $_POST['password'])) {
  8.         $username = mysql_real_escape_string($_POST['username']);
  9.         $password = mysql_real_escape_string($_POST['password']);
  10.        
  11.         if(empty($username) || empty($password))
  12.         {
  13.             echo "Please complete all fields.";
  14.         }
  15.        
  16.         if($username) {
  17.             //Check wheather the given username and password match if it does then the log the user in
  18.             //Otherwise tell the user the combination of username and password they provided was incorrect
  19.            
  20.             $sql = "SELECT `username` AND `password` FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
  21.             $res = mysql_query($sql) or die(mysql_error());
  22.             $result = mysql_num_rows($res);
  23.            
  24.             if($result > 0 ) {
  25.                 //Log the user in and set the session variables
  26.                 $id = getIdFromUsername($username);
  27.                 $userData = getInfoFromId($id);
  28.                 echo $userData['id'];
  29.             }else{
  30.                 //User provided incorrect information let the user know and ask them to try again.
  31.                 echo 'Wrong username and password combination';
  32.             }
  33.         }
  34.     }
  35. }
  36.  
  37. ?>
  38.  
  39. <html>
  40.     <head>
  41.         <title>Login    </title>
  42.     </head>
  43.     <body>
  44.         <div id="loginForm" align="center">
  45.             <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
  46.                 <p> Username: <input type="text" name="username" /> </p>
  47.                 <p> Password: <input type="password" name="password" /> </p>
  48.                 <input type="submit" name="login" value="Login" />
  49.             </form>
  50.        </div>
  51.     </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement