I have a 'Login' page. When people log in with the right combination of username and password from the database, they will be directed to another page ('input.html'). When the combination is wrong, they get an error.
Without logging in, I simply can change the name of the web address (from 'login.php' to 'input.html') and access the page. I want only Admin and Users to visit the page, not just 'visitors' without an account.
My code for my 'login.php'.
<?php
session_start();
$host = "localhost";
$user = "332547";
$pass = "cvEsbduv";
$db = "332547db";
mysql_connect($host, $user, $pass);
mysql_select_db($db);
if (!empty($_POST)) {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM inloggen2 WHERE username='".$username."' AND password='".$password."' LIMIT 1";
$res = mysql_query($sql);
if(mysql_num_rows($res) == 1) {
header('location: input.html');
exit ();
}else {
echo "Niet goed ingelogd. Keer alstubliefd terug naar de vorige pagina.";
header('location: foumelding.php');
exit();
}
}
?>
<html>
<head>
<title>Inloggen</title>
</head>
<body>
<table border="1">
<tr>
<td align="center">Inlogggen</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="login.php">
Gebruikersnaam: <input type="text" name="username" required/> <br /><br />
Wachtwoord: <input type="password" name="password" required/> <br /><br />
<input type="submit" name="submit" value="Log in" />
</form>
</table>
</td>
</tr>
</table>
</body>
</html>