Advertisement
Guest User

Untitled

a guest
Apr 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if (is_logged()) { //als ingelogged
  4. header("Location: welcome.php"); //ga naar welcome pagina
  5. }
  6.  
  7. function login($mysql,$username,$password){
  8. $sql = "SELECT * from GEBRUIKERS WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
  9. $result = $mysqli->query($sql);
  10. if (!$result->num_rows == 1) {
  11. return false;
  12. } else {
  13. return true;
  14. }
  15. }
  16. function is_logged() {
  17. if (isset($_SESSION['username'])) return true;
  18. //else return false;
  19. return false; //want als het niet gesset is dan return je false sowieso, dus geen `else` nodig.
  20. }
  21.  
  22. ?>
  23.  
  24.  
  25.  
  26. <html>
  27. <head>
  28. <title>Login</title>
  29. </head>
  30. <body>
  31. <?php
  32. if (!isset($_POST['submit'])){
  33. ?>
  34. <!-- The HTML login form -->
  35. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  36. Username: <input type="text" name="username" /><br />
  37. Password: <input type="password" name="password" /><br />
  38. <input type="submit" name="submit" value="Login" />
  39. </form>
  40. <?php
  41. } else {
  42. $username = $_POST["username"];
  43. $password = $_POST["password"];
  44. require_once("db_const.php"); //krijg de constanten (zoals je ze beneden ziet, ook niet echt veilig, maar ach)
  45. $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); //maak connectie aan
  46. if ($mysqli->connect_errno) { //check of er een connectie fout is
  47. echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
  48. exit();
  49. }
  50. if(login($mysqli,$usename,$password)){
  51. header("Location: welcome.php");
  52. }else{
  53. echo "Invalid username or password";
  54. }
  55. }
  56. mysqli_close($con)
  57. ?>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement