I have a login page where I am trying to detect if the user has activated their account and if they have check whether they are logged in. If they are logged in I want to check a DATETIME field to see if the time is 5 minutes ahead of their 'lasvisit' field. This is because the field 'loggedin' will not get updated to them being logged out if they didn't manually logout.
I am not sure how to go checking everything to see if it is only 5 minutes ahead.
Here is the code below:
<?php include "../Main/sublink.php";}
function in_content() {
$submitted = $_POST['submitted'];
$pseudonym = escape_data(strip($_POST['pseudonym']));
$password = escape_data(strip($_POST['password']));
$message = NULL;
if ($submitted) {
function login_request() {
$query3 = "UPDATE users SET loggedin='1', lastvisit=NOW() WHERE uid='$uid' LIMIT 1";
$result3 = @mysql_query($query3);
if (mysql_affected_rows() == 1) {
header ("Location: ../Main/index.php?sector=home");
exit;
} else {$message .= "<br>You could not be logged in; database write failure.";}
}
# Check pseudonym
if (!empty($pseudonym)) {
$ps = TRUE;
} else {
$message .= "<br>Please enter your pseudonym.";}
if (!empty($password)) {
$pw = TRUE;
} else {
$message .= "<br>Please enter your password.";}
if ($ps && $pw) {
$getdate = getdate();
$query1 = "SELECT active, uid FROM users WHERE pseudonym='$pseudonym' AND password=PASSWORD('$password')";
$result1 = @mysql_query($query1);
$row1 = mysql_fetch_array($result1, MYSQL_BOTH);
if ($row1['active'] == 1) {
$query9 = "SELECT loggedin, lastvisit FROM users WHERE pseudonym='$pseudonym' AND password=PASSWORD('$password')";
$result9 = @mysql_query($query9);
$row9 = mysql_fetch_array($result9, MYSQL_BOTH);
if (($row9['loggedin'] == 1) AND ($getdate+($getdate['minutes']+5) > $row1['lastvisit'])) {
$query2 = "SELECT uid, email FROM users WHERE pseudonym='$pseudonym' AND password=PASSWORD('$password')";
$result2 = @mysql_query($query2);
$row2 = mysql_fetch_array($result2, MYSQL_BOTH);
if ($row2) {
$_SESSION['uid'] = $row2['uid'];
$uid = $row2['uid'];
$_SESSION['pseudonym'] = $pseudonym;
$_SESSION['email'] = $row2['email'];
login_request();
} else {
$message .= "<br>You could not be logged in; database fetch failure.";}
} else {
$message .= "<br>You didn't logout and your 5 minute expiration time has not passed";}
} else {
$message .= "<br>Your account has not been activated for login yet.";}
} else {
$message .= "<br>Your login information was invalid; try again.";}
} else {}
?>
There are known operand errors with the $getdate but... I know it's probably log winded, but I am relatively new to PHP and am just trying to get this stuff working.