samona Posted May 15, 2008 Share Posted May 15, 2008 Hi all, I was hoping someone could help me with recording a user's last login date. I have a form that users use to login. There is an sql statement that checks whether the person is a valid user and allows them to login if a record matches. Is it at this time that I have to make another query to insert the date of the login? Thanks Link to comment https://forums.phpfreaks.com/topic/105751-solved-record-last-login-date/ Share on other sites More sharing options...
The Little Guy Posted May 15, 2008 Share Posted May 15, 2008 yes. $date = date("Y/m/d g:i:s"); Link to comment https://forums.phpfreaks.com/topic/105751-solved-record-last-login-date/#findComment-541836 Share on other sites More sharing options...
revraz Posted May 15, 2008 Share Posted May 15, 2008 When you do your query, just write NOW(), no need to use a variable or a PHP Date function. Link to comment https://forums.phpfreaks.com/topic/105751-solved-record-last-login-date/#findComment-541873 Share on other sites More sharing options...
The Little Guy Posted May 15, 2008 Share Posted May 15, 2008 When you do your query, just write NOW(), no need to use a variable or a PHP Date function. Yeah... Should have thought of that, but if you don't like the format of NOW() you can change it, but there are many ways to do this: NOW mysql_query("UPDATE table SET lastLog = 'NOW()' WHERE id = '{$row['userID']}"); date $date = date("m/d/Y g:i:s"); mysql_query("UPDATE table SET lastLog = '$date' WHERE id = '{$row['userID']}"); UNIX TIME STAMP $date = strtotime("now"); mysql_query("UPDATE table SET lastLog = '$date' WHERE id = '{$row['userID']}"); /* Most versatile, use the date function to format it easily This also makes it easy to sort/math/compare the dates if needed */ Link to comment https://forums.phpfreaks.com/topic/105751-solved-record-last-login-date/#findComment-541902 Share on other sites More sharing options...
samona Posted May 15, 2008 Author Share Posted May 15, 2008 The following is my code. Do I save it in a session variable like I have below to be able to display it on the other page? if ($user_name && $user_password) { $query = "Select User_ID, First_Name, User_Name, Last_Name, Is_Admin, Last_Login FROM Users WHERE User_Name='$user_name' AND User_Password='$user_password'"; $result = @mysql_query($query); $row = mysql_fetch_array($result, MYSQL_NUM); if($row) { $_Session['last_login'] = $row['Last_Login']; mysql_query("UPDATE table SET Last_Login = 'NOW()' WHERE id = '{$row['user_ID']}"); $result = @mysql_query($query); //Start the session, register the values and redirect. session_name('YourVisitID'); session_set_cookie_params(900, '/','website.com'); session_start(); $_SESSION['first_name'] = $row[1]; $_SESSION['user_id'] = $row[0]; $_SESSION['user_name'] = $row[2]; $_SESSION['last_name'] = $row[3]; $_SESSION['is_admin'] = $row[4]; header("Location: ./loggedin.php"); exit(); } Link to comment https://forums.phpfreaks.com/topic/105751-solved-record-last-login-date/#findComment-541910 Share on other sites More sharing options...
The Little Guy Posted May 15, 2008 Share Posted May 15, 2008 first off $_Session['last_login'] = $row['Last_Login']; session needs to be uppercase and second, yes you can if you want, or you can just make another query. Link to comment https://forums.phpfreaks.com/topic/105751-solved-record-last-login-date/#findComment-541920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.