ACwarrior Posted August 8, 2009 Share Posted August 8, 2009 Hi! I have a normal log in script that log the last login time. I need to find out the total number of time a user log in so far. What I need is a php script that record and add everytime a user log in. I am using SQL to store the data. Anyone can kindly help in providing a simple script for this? I am noob in php and search the whole www for temple but Thanks Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted August 8, 2009 Share Posted August 8, 2009 Something like this.. simplified <?php if (user_just_logged_in_again) { $sql = "UPDATE some_table SET total_logins = total_logins + 1 WHERE user_id = $userID"; mysql_query($sql) or die(mysql_error); } Quote Link to comment Share on other sites More sharing options...
ACwarrior Posted August 8, 2009 Author Share Posted August 8, 2009 Thanks... no reported run error there but it is not updating in my sql. what could be wrong. I set the variable according... Quote Link to comment Share on other sites More sharing options...
trq Posted August 8, 2009 Share Posted August 8, 2009 When are you executing this piece of code? Quote Link to comment Share on other sites More sharing options...
ACwarrior Posted August 8, 2009 Author Share Posted August 8, 2009 <?php // Function to validate user function ValidateUser($Username,$Password) { global $HTTP_SESSION_VARS; $ValidateUser = false; $CaseSensitive = false; // Modify case sensitivity here $AdminUsername = "administrator"; $AdminPassword = "admin"; // Check hard coded admin first if ($CaseSensitive) { $ValidateUser = ($AdminUsername == $Username && $AdminPassword == $Password); } else { $ValidateUser = (strtolower($AdminUsername) == strtolower($Username) && strtolower($AdminPassword) == strtolower($Password)); } if ($ValidateUser) { // System admin $HTTP_SESSION_VARS[ewSessionStatus] = "login"; $HTTP_SESSION_VARS[ewSessionSysAdmin] = 1; $HTTP_SESSION_VARS[ewSessionUserID] = -1; $HTTP_SESSION_VARS[ewSessionUserLevel] = -1; SetUpUserLevel(); } // Check other users if (!$ValidateUser) { $conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT); $Username = (!get_magic_quotes_gpc()) ? addslashes($Username) : $Username; $sFilter = "(`UserID` = '" . AdjustSql($Username) . "')"; $sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, ""); $query = phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql); if (phpmkr_num_rows($query) > 0) { $rs = phpmkr_fetch_array($query); if ($CaseSensitive) { $ValidateUser=($rs["Password"] == $Password); } else { $ValidateUser=(strtolower($rs["Password"]) == strtolower($Password)); } if ($ValidateUser) { $HTTP_SESSION_VARS[ewSessionStatus] = "login"; $HTTP_SESSION_VARS[ewSessionUserName] = $rs["UserID"]; $HTTP_SESSION_VARS[ewSessionSysAdmin] = 0; // Non system admin $HTTP_SESSION_VARS[ewSessionUserID] = $rs["ID"]; // User ID $HTTP_SESSION_VARS[ewSessionParentUserID] = $rs["Report_To"]; // Parent User ID $HTTP_SESSION_VARS[ewSessionUserLevel] = $rs["Userlevel"]; // User Level if ($HTTP_SESSION_VARS[ewSessionUserLevel] == -1) { // System admin $HTTP_SESSION_VARS[ewSessionUserID] = -1; } SetUpUserLevel(); } } phpmkr_free_result($query); phpmkr_db_close($conn); } return $ValidateUser; } ?> This is part of my login script... where should i put this code in? Quote Link to comment Share on other sites More sharing options...
ACwarrior Posted August 10, 2009 Author Share Posted August 10, 2009 <?php // Function to validate user function ValidateUser($Username,$Password) { global $HTTP_SESSION_VARS; $ValidateUser = false; $CaseSensitive = false; // Modify case sensitivity here $AdminUsername = "administrator"; $AdminPassword = "admin"; // Check hard coded admin first if ($CaseSensitive) { $ValidateUser = ($AdminUsername == $Username && $AdminPassword == $Password); } else { $ValidateUser = (strtolower($AdminUsername) == strtolower($Username) && strtolower($AdminPassword) == strtolower($Password)); } if ($ValidateUser) { // System admin $HTTP_SESSION_VARS[ewSessionStatus] = "login"; $HTTP_SESSION_VARS[ewSessionSysAdmin] = 1; $HTTP_SESSION_VARS[ewSessionUserID] = -1; $HTTP_SESSION_VARS[ewSessionUserLevel] = -1; SetUpUserLevel(); } // Check other users if (!$ValidateUser) { $conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT); $Username = (!get_magic_quotes_gpc()) ? addslashes($Username) : $Username; $sFilter = "(`UserID` = '" . AdjustSql($Username) . "')"; $sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, ""); $query = phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql); if (phpmkr_num_rows($query) > 0) { $rs = phpmkr_fetch_array($query); if ($CaseSensitive) { $ValidateUser=($rs["Password"] == $Password); } else { $ValidateUser=(strtolower($rs["Password"]) == strtolower($Password)); } $username = $_POST['username']; $password = $_POST['password']; $search_user_query = "SELECT * FROM " . employees . " WHERE `" . UserID . "`='$Username' AND `" . Password . "`='$password'"; $search_user_result = @mysql_query($search_user_query); $query2 = mysql_query("UPDATE ". table ." SET count =(count + 1), report_to=NOW() WHERE ". UserID. "='$Username'"); if ($ValidateUser) { $HTTP_SESSION_VARS[ewSessionStatus] = "login"; $HTTP_SESSION_VARS[ewSessionUserName] = $rs["UserID"]; $HTTP_SESSION_VARS[ewSessionSysAdmin] = 0; // Non system admin $HTTP_SESSION_VARS[ewSessionUserID] = $rs["ID"]; // User ID $HTTP_SESSION_VARS[ewSessionParentUserID] = $rs["Report_To"]; // Parent User ID $HTTP_SESSION_VARS[ewSessionUserLevel] = $rs["Userlevel"]; // User Level if ($HTTP_SESSION_VARS[ewSessionUserLevel] == -1) { // System admin $HTTP_SESSION_VARS[ewSessionUserID] = -1; } SetUpUserLevel(); } } phpmkr_free_result($query); phpmkr_db_close($conn); } return $ValidateUser; } ?> This is part of my login script... where should i put this code in? I solved it As the bold part. This login can now record the last login time and count the number of time a user login. Thanks Tendolla for your rough template. Quote Link to comment Share on other sites More sharing options...
juicyscript Posted October 2, 2009 Share Posted October 2, 2009 Hi acworrior Can i get this script...am also new to php and i've been looking for a script like this Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.