Jump to content

Script that Count number of times a user log in


ACwarrior

Recommended Posts

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

<?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?

 

<?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  :D 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.

  • 1 month later...

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.