Advertisement
Guest User

Authenticate.php

a guest
Jan 18th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $DB_HOST = 'localhost';
  4. $DB_USER = 'cyberwol';
  5. $DB_PASS = 'm74c3tg^vxmpH8t7aVj9';
  6. $DB_NAME = 'phplogin';
  7. $con = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
  8. if ( mysqli_connect_errno() ) {
  9.     die ('Failed to connect to MySQL: ' . mysqli_connect_error());
  10. }
  11. if ( !isset($_POST['username'], $_POST['password']) ) {
  12.     die ('Username and/or password does not exist!');
  13. }
  14. if ($stmt = $con->prepare('SELECT id, password FROM accounts WHERE username = ?')) {
  15.     $stmt->bind_param('s', $_POST['username']);
  16.     $stmt->execute();
  17.     $stmt->store_result();
  18.     if ($stmt->num_rows > 0) {
  19.         $stmt->bind_result($id, $password);
  20.         $stmt->fetch();      
  21.         if ($_POST['password']==$password) {
  22.             $_SESSION['loggedin'] = TRUE;
  23.             $_SESSION['name'] = $_POST['username'];
  24.             $_SESSION['id'] = $id;
  25.             echo 'Welcome ' . $_SESSION['name'] . '!';
  26.             header('Location: https://x-sim.co.uk/home.php');  
  27.         } else {
  28.             header('Location: https://x-sim.co.uk/loginfailed.html');
  29.         }
  30.     } else {
  31.         header('Location: https://x-sim.co.uk/loginfailed.html');
  32.     }
  33.     $stmt->close();
  34. } else {
  35.     echo 'Could not prepare statement!';
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement