I have a login script that check a DB for username and password and logs the user in. I want to add the last login time to the sript as well.
I have a control panel as the first page that the user sees upon login and the other pages have alonk to return to control panel page.
Everytime the users return to the control panel page the update the login time script gets execued again and overwrites the last login time info in the DB.
How can I get this part to only exeute once during this seeesion the user is logged in.
<?php
session_start();
if ((!$username) && (!$password)) {
header("Location: /npi/index.php?error=5");
exit;
}elseif(!$username) {
header("Location: /npi/index.php?error=3");
exit;
}elseif (!$password) {
header("Location: /npi/index.php?error=4");
exit;
}else{
$Host = "localhost";
$User = "****";
$Password = "****";
$DBName = "****";
$thedate = date("F j, Y g:i a");
$Link = mysql_connect ($Host, $User, $Password) or die ("The database connection could not be established!");
$query = "SELECT * from health_login where username='$username' AND password='$password'";
$result = mysql_db_query($DBName, $query, $Link) or die("Could not complete database query");
$total = mysql_num_rows($result);
}
if ($total == 1){
$username = "$username";
$password = "$password";
session_register('username');
session_register('password');
$query3 = "UPDATE health_login SET last_login = '$thedate' WHERE username = '$username'";
$result = mysql_db_query($DBName, $query3, $Link) or die("Could not complete database query");
}
?>
Thanks,
Stan