Ok, as with any problem I have this is probably a result of laziness somewhere on my part, but I have no clue where
I am using an object, in a session variable to track users, so far, its worked great!
But I just noticed, that I can't seem to log in the first time I try, I get no error messages, simply redirected to my main page (like whats supposed to happen after I log in
Its getting confusing, I've look through every bit of the script but I can't figure it out.
Here is the login function in the user class:
<?php
function login($user, $pass) {
// Check if the user is already logged in
if ($this->login == TRUE) {
header('Location: index.php');
}
global $db;
global $site;
if (!$db) {
die('NO DATABASE CONNECTION FOUND');
}
$sql = 'SELECT * FROM `users` WHERE ';
$sql .= "username='$user' AND password=SHA1('$pass')";
$query = $db->query($sql);
if ($query->numrows != 1) {
$this->error_message("Invalid Username or password");
header('Location: '.$site['dir_root'].'/login.php');
} else {
$info = $query->data[0];
$this->username = $info['username'];
$this->uid = $info['uid'];;
$this->login = TRUE;
}
}
?>
And here is the auth.php script:
<?php
require_once('setup.php');
if (!isset($_POST['username']) || (!isset($_POST['password']))) {
$_SESSION['user']->error_message("Please enter a username and password!");
header('Location: login.php');
}
$_SESSION['user']->login(addslashes($_POST['username']), addslashes($_POST['password']));
$page = addslashes($_POST['redirect']);
header('Location: '.$page);
?>
I'm not sure what the problem is, the first time I try to log in, I get redirected back to the home page with no change to the $_SESSION['user'] object, the second time I get logged in like I should.
Any help is greatly appreciated, its not a major issue right now but it'll be great to get it out of the way and not have to solve it later (and it would be nice to only have to log in once)
If there is any more info I can provide to make solving this easier, please ask 🙂