Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if (is_logged()) {
- header("Location: welcome.php");
- }
- function login($mysqli,$username,$password){
- $sql = "SELECT * from GEBRUIKERS WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
- $result = $mysqli->query($sql);
- if (!$result->num_rows == 1) {
- return false;
- } else {
- $_SESSION["username"] = $username;
- return true;
- }
- }
- function is_logged() {
- if (isset($_SESSION['username'])) return true;
- return false;
- }
- ?>
- <html>
- <head>
- <title>Login</title>
- </head>
- <body>
- <?php
- if (!isset($_POST['submit'])){
- ?>
- <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
- Username: <input type="text" name="username" /><br />
- Password: <input type="password" name="password" /><br />
- <input type="submit" name="submit" value="Login" />
- </form>
- <?php
- } else {
- $username = $_POST["username"];
- $password = $_POST["password"];
- require_once("db_const.php");
- $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
- if ($mysqli->connect_errno){
- echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
- exit();
- }
- if(login($mysqli,$usename,$password)){
- header("Location: welcome.php");
- }else{
- echo "Invalid username or password";
- }
- mysqli_close($mysqli);
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement