Hjælp til php login
Jeg har lavet et login system i php. Men det virker ikke :(Når jeg skriver et forkert brugernavn/password, og klikker på login knappen, logger den bare ind. Håber i kan hjælpe mig.
koden
index.php
<?php
session_start();
if(isset($_SESSION['user'])){
header('Location: profile.php');
}else{
header('index.php');
}
?>
<html>
<head>
<style>
body {
background-color:#D9D9D9;
font-family:Arial;
font-size:13px;
}
.corner {
background-color:#FFFFFF;
margin: 0 auto;
width:600px;
height:170px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
#link {
color:black;
text-decoration:underlined;
}
#link:hover {
color:red;
text-decoration:none;
}
</style>
<title>Login</title>
</head>
<body>
<center>
<div class="corner">
<form method="post" action="index.php">
<h3>Login</h3>
Username: <input type="text" name="username"><br/>
Password: <input type="password" name="password"></br>
<input type="submit" name="login" value="Login"><br/>
</form>
Do you not have a account? <a href="register/register.php" id="link">register here</a><br/>
</body>
</html>
<?php
if (isset($_POST['login'])) {
include "login_connect.php";
$username = htmlentities(mysql_real_escape_string($_POST['username']));
$password = htmlentities(mysql_real_escape_string(sha1($_POST['password'])));
$query = mysql_query("SELECT * FROM members WHERE username = '$username' AND password = '$password'");
$data = mysql_fetch_assoc($query);
if(mysql_num_rows($query)) {
$_SESSION['user'] = "$username";
header("Location: profile.php");
} else {
header("Location: index.php");
echo "Wrong username/password";
}
}
?>
</div>
</center>