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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.