PHP Question

C++, C#, Java, PHP, ect...
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

PHP Question

Post by SpiritWebb »

Using php and mysql, how do I set it in the database to call a last time you logged in function? I want it too when you log in again, it will tell you the last time you logged in. Confused, how do I set this up? Thanks in advance...
Image

Image
User avatar
Sakar
Posts: 520
Joined: Thu Apr 23, 2009 2:59 am

Re: PHP Question

Post by Sakar »

Take a look at this to get you started: http://php.about.com/od/learnphp/ss/php_functions_2.htm
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: PHP Question

Post by SpiritWebb »

Thanks Sakar, but what I'm needing is to be able to use MySql and the PHP to use the date function.

For example: You logout say, 8-8-09 right. Then you login again say 8-15-09 and you get in the game, I want it to say, "Last login: 8-8-09." So it keeps track of the last time you played the game.

Thats what I'm trying to figure out.
Image

Image
User avatar
Noctrine
Posts: 928
Joined: Thu Apr 23, 2009 9:57 pm

Re: PHP Question

Post by Noctrine »

http://us2.php.net/manual/en/function.date.php is the date function. After you get that, all you need to do is check the last time you logged in before updating that column in their row.

Either that or making a login tracking table.
Jesse Dorsey
ProjectANI - Lead Developer Person
http://about.me/jessedorsey
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: PHP Question

Post by Jackolantern »

SpiritWebb wrote:Using php and mysql, how do I set it in the database to call a last time you logged in function? I want it too when you log in again, it will tell you the last time you logged in. Confused, how do I set this up? Thanks in advance...
Sounds like you need to use TIMESTAMP. When a column is set to TIMESTAMP, it automatically records the time and date of the last action on that record if you do not set it manually. It's quite handy :D
The indelible lord of tl;dr
User avatar
Noctrine
Posts: 928
Joined: Thu Apr 23, 2009 9:57 pm

Re: PHP Question

Post by Noctrine »

Ah, I totally forgot about TIMESTAMP. Yes, I would recommend using that, but If I remember correctly timestamp works by counting the milliseconds since some arbitrary time. He would have to write/find a script to put it in the format he wants.
Jesse Dorsey
ProjectANI - Lead Developer Person
http://about.me/jessedorsey
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: PHP Question

Post by Torniquet »

this is the way i done it...

when you log in and the sessions are set. follow it with an update like:

mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id'");

then to call it up again on your profile page or where ever you want to display it. you need to include the 'last_log_in' feild in your array.

$last_log_date = $row["last_log_date"];

followed by

$last_log_date = strftime("%b %d, %Y", strtotime($last_log_date));


thats the way i do it. so when it writes it to the DB its formatted: YYYY-MM-DD (2009-08-08)
then when its called again it formats it: DD Month YYYY (08 August 2009)

if you need to know how to set up the DB feild let me know and i shall post it up. :)

hope that helps and is what your looking for :p

EDIT -- ok re read what you put lol. and come to realise thats not what you was after :p

anyway hope it helps some1. if i can think of a way to do it ill post up :)
New Site Coming Soon! Stay tuned :D
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: PHP Question

Post by SpiritWebb »

Jackolantern wrote:
SpiritWebb wrote:Using php and mysql, how do I set it in the database to call a last time you logged in function? I want it too when you log in again, it will tell you the last time you logged in. Confused, how do I set this up? Thanks in advance...
Sounds like you need to use TIMESTAMP. When a column is set to TIMESTAMP, it automatically records the time and date of the last action on that record if you do not set it manually. It's quite handy :D
TIMESTAMP? I looked it up to learn about it, but I don't understand how to setup TIMESTAMP to create a date that shows "Last Login: xx-xx-xxxx" where x=the date. I keep seeing how to convert numbers into a readable date, and cant seem to find what i want it too do...so lost...
Image

Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: PHP Question

Post by SpiritWebb »

Torniquet wrote:this is the way i done it...

when you log in and the sessions are set. follow it with an update like:

mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id'");

then to call it up again on your profile page or where ever you want to display it. you need to include the 'last_log_in' feild in your array.

$last_log_date = $row["last_log_date"];

followed by

$last_log_date = strftime("%b %d, %Y", strtotime($last_log_date));


thats the way i do it. so when it writes it to the DB its formatted: YYYY-MM-DD (2009-08-08)
then when its called again it formats it: DD Month YYYY (08 August 2009)

if you need to know how to set up the DB feild let me know and i shall post it up. :)

hope that helps and is what your looking for :p

EDIT -- ok re read what you put lol. and come to realise thats not what you was after :p

anyway hope it helps some1. if i can think of a way to do it ill post up :)
I tried it your way...placing the mysql_querry into the authenticate.php file and the other in the index.php file, but i get an error, saying undefined index $row.
Image

Image
jpoisson
Posts: 245
Joined: Sun Aug 02, 2009 5:12 pm

Re: PHP Question

Post by jpoisson »

I am not sure if this will help you but I have been working on my own date time functions, no suprise there. I use varchar(25) for my coloum settings. Why would i do this well in your authentication page you can creat a variable
called $datetime and the row can be called what ever.

Code: Select all

$datetime = date("d/m/y h:i:s"); //create date time
the date() function will grab the latest time and I am formatting it in a way so it is readable instead of a bunch of random numbers.

xx/xx/xx/ xx:xx:xx will be the out put for that variable.

then you update the column where you are storing the time with this variable. 
Laguages:
PHP, MYSQL, (X)HTML, HTML5, JQuery, CSS 3.0,
C, C#, C++, Python, Pascal, Perl, Ruby, Turing

Software:
Adobe MC CS4, Visual Studio 2008, Notepad++,
NetBeans IDE, WAMPSERVER

Browsers:
Internet Explorer, Firefox, Opera, Safari, Chrome
(Always have latest patches for browsers.)

Free time:
...
Post Reply

Return to “Coding”