ljr747
08-12-2008, 08:47 PM
Hey guys, I'm building a register/login script. The register works fine as it sends the information to a database which I have checked and it works. The login works but it doesn't seem to keep me logged in?! Heres my login code:
<?php
session_start();
include 'database.php';
if($logged[username]) {
echo 'header ("Location: index.php")';
} else {
if(isset($_POST['login'])) {
$username = ($_POST['username']);
$password = ($_POST['password']);
if(!$username | !$password) {
echo ("A field has been left blank!");
} else {
$find = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'");
if ($uzes = mysql_num_rows($find) == '0') {
echo ("This username doesn't exist!");
} else {
$query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'");
$array = mysql_fetch_array($query);
$_SESSION['id'] = "$user[id]";
$_SESSION['password'] = "$user[password]";
echo ("You are now logged in!");
echo ("<meta http-equiv='Refresh' content='5; URL=index.php'>");
}
}
} else {
echo ("<form method='post' action='$_SERVER[PHP_SELF]'>
Username:<br>
<input type='text' name='username' size='30'><br>
Password:<br>
<input type='password' name='password' size='30'><br>
<input type='submit' name='login' value='Login'>
</form>");
}
}
?>I know I haven't slated or md5'd the passwords but I will do after it's fixed, it directs me to index.php but when I go back to the login.php page it asks me to login again? :S
PLEASE HELP!!
<?php
session_start();
include 'database.php';
if($logged[username]) {
echo 'header ("Location: index.php")';
} else {
if(isset($_POST['login'])) {
$username = ($_POST['username']);
$password = ($_POST['password']);
if(!$username | !$password) {
echo ("A field has been left blank!");
} else {
$find = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'");
if ($uzes = mysql_num_rows($find) == '0') {
echo ("This username doesn't exist!");
} else {
$query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'");
$array = mysql_fetch_array($query);
$_SESSION['id'] = "$user[id]";
$_SESSION['password'] = "$user[password]";
echo ("You are now logged in!");
echo ("<meta http-equiv='Refresh' content='5; URL=index.php'>");
}
}
} else {
echo ("<form method='post' action='$_SERVER[PHP_SELF]'>
Username:<br>
<input type='text' name='username' size='30'><br>
Password:<br>
<input type='password' name='password' size='30'><br>
<input type='submit' name='login' value='Login'>
</form>");
}
}
?>I know I haven't slated or md5'd the passwords but I will do after it's fixed, it directs me to index.php but when I go back to the login.php page it asks me to login again? :S
PLEASE HELP!!