Guest User

Untitled

a guest
Jul 29th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. <form method="POST" action="verification.php" class="loginFields">
  2. <input type="text" name="username" placeholder="Username" autofocus>
  3. <input type="password" name="password" placeholder="Password">
  4. <input type="submit" name="submit" value="Inloggen">
  5. </form>
  6.  
  7. // Start new DOMDocument and load html file.
  8. $dom = new DOMDocument();
  9. libxml_use_internal_errors(true);
  10. $dom->loadHTMLFile("loginHTML.html");
  11. libxml_use_internal_errors(false);
  12.  
  13. // Haal verification.php op om gegevens te checken.
  14. include_once('verification.php');
  15.  
  16.  
  17. if(isset($_POST['submit'])){
  18. $username = $_POST['username'];
  19. $password = $_POST['password'];
  20.  
  21. $object = new user();
  22. $object->login($username, $password);
  23. }
  24. // Save DOMDocument with html document.
  25. echo $dom->saveHTML();
  26.  
  27. // Include connection.php om connectie te maken te de database.
  28. include_once('inc/connection.php');
  29. include_once('login.php');
  30.  
  31. class user{
  32.  
  33. private $db;
  34.  
  35. public function __construct(){
  36. $this->db = new connection();
  37. $this->db = $this->db->dbconnect();
  38. }
  39.  
  40.  
  41. public function login($username, $password){
  42. $this->db = new Connection();
  43. $this->db = $this->db->dbConnect();
  44.  
  45. // Als $username en $password gevuld zijn checken op overeenkomst
  46. if(!empty($username) && !empty($password)){
  47. $st = $this->db->prepare("SELECT * FROM users WHERE username=? AND password=?");
  48. $st->bindParam(1, $username);
  49. $st->bindParam(2, $password);
  50. $st->execute();
  51. $result=$st->fetch(PDO::FETCH_ASSOC);
  52. $id=$result['id'];
  53.  
  54. // Als er een overeenkomst is doorsturen naar admin.php en session aanmaken
  55. if($st->rowCount() == 1) {
  56. $_SESSION['id'] = $result['id'];
  57. $_SESSION['ingelogt'] = $username;
  58. header('location: admin.php');
  59. exit;
  60. } else {
  61. echo "Incorrect username or password";
  62. }
  63.  
  64. // Als er niks is ingevoerd bij het inlogscherm
  65. } else {
  66. echo "Please enter your username and password";
  67. }
  68. }
  69. }
  70.  
  71. session_start();
  72. // If session is not ingelogt lead back to index.php.
  73. if(!isset($_SESSION['id'])) {
  74. header("location: index.php");
  75. die();
  76. }
  77.  
  78. //...
  79. $st->execute();
  80. $row = $st->fetch();
  81.  
  82. $id = $row['id'];
Add Comment
Please, Sign In to add comment