Advertisement
Guest User

Untitled

a guest
Apr 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if (is_logged()) {
  4. header("Location: welcome.php");
  5. }
  6. function login($mysqli,$username,$password){
  7. $sql = "SELECT * from GEBRUIKERS WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
  8. $result = $mysqli->query($sql);
  9. if (!$result->num_rows == 1) {
  10. return false;
  11. } else {
  12. $_SESSION["username"] = $username;
  13. return true;
  14. }
  15. }
  16. function is_logged() {
  17. if (isset($_SESSION['username'])) return true;
  18. return false;
  19. }
  20. ?>
  21. <html>
  22. <head>
  23. <title>Login</title>
  24. </head>
  25. <body>
  26. <?php
  27. if (!isset($_POST['submit'])){
  28. ?>
  29. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  30. Username: <input type="text" name="username" /><br />
  31. Password: <input type="password" name="password" /><br />
  32. <input type="submit" name="submit" value="Login" />
  33. </form>
  34. <?php
  35. } else {
  36. $username = $_POST["username"];
  37. $password = $_POST["password"];
  38. require_once("db_const.php");
  39. $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  40. if ($mysqli->connect_errno){
  41. echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
  42. exit();
  43. }
  44. if(login($mysqli,$usename,$password)){
  45. header("Location: welcome.php");
  46. }else{
  47. echo "Invalid username or password";
  48. }
  49. mysqli_close($mysqli);
  50. }
  51.  
  52. ?>
  53. </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement