function lastLogin() {
// Show the date and time in the timezone
global $_SESSION;
$username = $_SESSION["user"]["username"];
$query = db_query("SELECT timezone, lastlog FROM users WHERE username = '$username'");
$result = db_fetch_object($query);
// Date, Time and Timezone
$date = "F j, Y";
$format = "g:i a";
$tz = "$result->timezone";
$lastlog = "$result->lastlog";
$time = createDate($format, time(), $tz);
echo '<p>It is currently '. date($date) .' and the time is '. $time .'. ';
if (date($date, $lastlog) == date($date)) {
echo 'Your last logon was Today.</p>';
} elseif (date($date, $lastlog) == date($date, strtotime("-1 day"))) {
echo 'Your last logon was Yesterday.</p>';
} else {
$last = date($date, $lastlog);
echo 'Your last logon was at '. $last .'.</p>';
}
}
last login script notworking?
Started by tiki, Jan 16 2006 05:08 AM
10 replies to this topic
#1
Posted 16 January 2006 - 05:08 AM
I have a last login script, the last login part aint working it echos this everytime: It is currently January 16, 2006 and the time is 2:06 am. Your last logon was at December 31, 1969. So just the ending is wrong, aswell the lastlogin table is timestamp.
#2
Posted 16 January 2006 - 09:39 AM
What is the structure for the table. Possibly you have the length for the timestamp table wrong. So it automatically cuts off the excess data.
#3
Posted 16 January 2006 - 01:40 PM
There is no length for the timestamp. Just default is 00-00-00 shit as usual.
#4
Posted 16 January 2006 - 06:17 PM
Try and do the same sorta thing i told you to do here:
http://www.pixel2life.com/forums/index.php...indpost&p=12018
Make sure all the variables are right.
Note: If the timestamp stored in the database follows the "00-00-00" pattern, then the date function won't work properly, and that would be what you need to fix. You can take a look at strtotime to do that for you (you can also search the forms for "date", i remember a slight discussion about it here).
http://www.pixel2life.com/forums/index.php...indpost&p=12018
Make sure all the variables are right.
Note: If the timestamp stored in the database follows the "00-00-00" pattern, then the date function won't work properly, and that would be what you need to fix. You can take a look at strtotime to do that for you (you can also search the forms for "date", i remember a slight discussion about it here).
Edited by rc69, 16 January 2006 - 06:19 PM.
#5
Posted 16 January 2006 - 06:58 PM
Well if I change the timestamp row to a date type instead would that work, because I dont need the time, just the date.
#6
Posted 16 January 2006 - 08:57 PM
If you keep using the date function, no, it won't make a difference.
The only thing you could do is change it's type to int, and adjust the query you use to insert the login info to add the current time() to the database. Or do what i said in my last post...
Personally, i prefer to store the time() in the database rather then all the other stuff, but it's up to you.
The only thing you could do is change it's type to int, and adjust the query you use to insert the login info to add the current time() to the database. Or do what i said in my last post...
Personally, i prefer to store the time() in the database rather then all the other stuff, but it's up to you.
#7
Posted 17 January 2006 - 01:22 AM
Hmm this is actually pointless.
Because when you login it adds the new timestamp, so therefor it will always show the current date for your last logon, I mite aswell remove this.
Because when you login it adds the new timestamp, so therefor it will always show the current date for your last logon, I mite aswell remove this.
#8
Posted 17 January 2006 - 04:36 PM
Well, if you decide to take another wack at it, just have it read the last date and store it in a variable before you update it...
#9
Posted 17 January 2006 - 06:14 PM
i may add that later but for now ill get the other stuff i needed done.
#10
Posted 17 January 2006 - 08:40 PM
tiki, on Jan 17 2006, 06:22 AM, said:
Hmm this is actually pointless.
Because when you login it adds the new timestamp, so therefor it will always show the current date for your last logon, I mite aswell remove this.
Because when you login it adds the new timestamp, so therefor it will always show the current date for your last logon, I mite aswell remove this.
you made it more complicated then it needs to be. for it to work you most likely need two date fields and a way to determine whether to update the last time of login. something along the lines of checking to see if recent_login2 is greater then x seconds or minutes then update recent_login = recent_login2... so recent_login2 would store the MOST recent login and recent_login would store the least recent login.
#11
Posted 18 January 2006 - 12:24 AM
zealivity5, on Jan 18 2006, 01:40 AM, said:
you made it more complicated then it needs to be. for it to work you most likely need two date fields and a way to determine whether to update the last time of login. something along the lines of checking to see if recent_login2 is greater then x seconds or minutes then update recent_login = recent_login2... so recent_login2 would store the MOST recent login and recent_login would store the least recent login.
Thats true, but I wouldnt know how to do that =P
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
