Jump to content

[SOLVED] Last Logged in


Gubbins

Recommended Posts

I have tried various ways to find out when the people on my web site last logged in!

I cant seem to get it right!

I would like to add it to there profiles so we can all see who is active and so on!

I know i will need to add a table into the database to for the info to be stored!

Can anyone help please?

Kind regards

Gubbins

 

Link to comment
https://forums.phpfreaks.com/topic/129107-solved-last-logged-in/
Share on other sites

You could use the date() function when the user logs in to get the time and then insert it into your  user table. Something like this:

 

<?php

// Login check and use of the date() function here

$sql = "INSERT INTO users WHERE username = '$username' (lastlogin) VALUES ('$date')";
$result = mysql_query($sql) or die(mysql_error());

if ($result)

{

$row = mysql_fetch_array($result))

echo $row['lastlogin'];

}

?>

 

Try something like that. Never actually did it before so I'm not 100% if the query is structured correctly. Give it a show and good luck! :)

Thank you for replying so fast!

Do i add that into the profile.php file?

Also

I dont use user and username but i can easily change that!

 

Do i need an entry into the players section of the database and if so would the name be lastlogin?

i.e.

Field, lastlogin

Type, date

Default, 0000-00-00

Add a field last_active (varchar 255) in the players table, and add this to your connections/requires.php script...

 

$act = gmdate('M, dS, Y, h:i A');

mysql_query("UPDATE players SET last_active = '$act' WHERE playername = '$player' LIMIT 1")or trigger_error(mysql_error());

 

Then echo it out in a field on profiles...

 

//Edit // Edited date format.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.