maxa
|
| Posted: 06/20/2005, 5:19 AM |
|
Hi,
how to make a counter on login page to see on admin page how many times some user login on site ???
php+mysql
Regards,
maxa
|
|
|
 |
wkempees
Posts: 1679
|
| Posted: 06/20/2005, 10:41 AM |
|
Create a table in the database called (something like) logging.
storing an id (autoincrement key), user_id, date, time and any other fields you like (we use browser type, ipnr and so on).
After successful login insert a row into the logging table.
The id will be autoincremented, you fill user_id the users' id and so on.
On the one hand it will give you a great logging file.
On the other hand you could do a count(*) from logging where user_id = {a value}, giving you the number of times a user logged in (successfully).
Create a grid on the logging table using the above count(*) will please your administrator, even the "drill-down" (build a grid per row on the previous grid) capability will put an even greater smile on his face.
Varying the where clause to contain a period will give you all the flex you need.
Additionally build a logging function adding rows as users move through your application, calling the function on each page_load.
Beacuse the next question your administrator is going to pose is: How long has this user been logged in.
Web applications are state-less so by supplying the last action the user took you can somewhat estimate the usage.
Or build a real tight log_out sequence, but (like in the fairy-tales) that's a completely different story.................
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
maxa
|
| Posted: 06/21/2005, 4:09 AM |
|
Thx wkempees,
first you have confused me, then I have get some ideas and then I have done it very simple:
On login page click on login button, then go to events-on click-login and you will get:
--------------------------------------------------------------------
//Login @22-0F36C61E
global $Login1;
if(!CCLoginUser($Login1->login->Value, $Login1->password->Value))
{
$Login1->Errors->addError("Login or Password is incorrect.");
$Login1->password->SetValue("");
$Login1_Button_DoLogin_OnClick = false;
}
else
{
global $Redirect;
$Redirect = CCGetParam("ret_link", $Redirect);
$Login1_Button_DoLogin_OnClick = true;
//this is my code i have add when the user have successful login:))
$db = new clsDBConnection1();
$current_date = date('Y-m-d H:i:s');
$SQL = "UPDATE user2 SET access=access+1, datum='" . $current_date . "' WHERE id=" . CCGetUserid() . "";
$db->query($SQL);
$db->close();
}
//End Login
--------------------------------------------------------------------
and its working great:))
Regards,
maxa
|
|
|
 |
wkempees
Posts: 1679
|
| Posted: 06/21/2005, 6:59 AM |
|
Glad it got you going.
Meanwhile I received private message from someone requesting a sample.
I have made a sample and will post it later today.
Roughly it comprises of:
Adding a table to your database.
Adding a small function to your common.php
Adding the line [source]
logging();
[/source]
or [source]
logging("a message you want to stamp into your logging file");
[/source]
to any "before show" of any form/grid you want to have logged.
This could also be in your after logon.
greetz
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 06/21/2005, 7:14 AM |
|
This code into common.php of your current project add it to the very end of the file:
[source]
//WKLogging
function logging($message)
{
$db = new clsDBIntranetDB(); //your connection here
$SQL = "INSERT into logging (
user_id, datestamp, logmsg, ipnr ) values ("
. $db->ToSQL(CCGetSession("UserID"),ccsText)
.",". $db->ToSQL(date('Y-m-d H:i:s'),ccsText)
.",". $db->ToSQL( $message,ccsText)
.",". $db->ToSQL($_SERVER['REMOTE_ADDR'] .'-'. $_SERVER['HTTP_USER_AGENT'],ccsText)
." )";
$db->query($SQL);
$db->close();
return $Result;
}
//End WKLogging
[/source]
Create a table in your database something like this:
[source]
CREATE TABLE `logging` (
`id` mediumint(9) NOT NULL auto_increment,
`user_id` mediumint(9) NOT NULL default '0',
`datestamp` varchar(20) default NULL,
`logmsg` varchar(128) default NULL,
`ipnr` varchar(128) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM
[/source]
From now on just put
logging();
in your source and a record will be placed in the logging table.
logging("just a message");
will add the message to the logfile.
Now you are able to do SELECTs on LOGGING table giving you whatever data you need.
select count() from logging where user_id = 'nn' and datestamp ......
and so on.
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
maxa
|
| Posted: 06/21/2005, 7:46 AM |
|
thx for this code its workin great to
|
|
|
 |
wkempees
Posts: 1679
|
| Posted: 06/21/2005, 1:59 PM |
|
Build you an example at http://dawn.paginaatje.nl
Working example, slow connection, zip file downloadable.
Build CCS3.0 PhP MySql
Have fun and please let me know if I spent my time well.
Walter Kempees
The Netherlands
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
Jason Bragg
|
| Posted: 07/26/2005, 5:57 AM |
|
How could this be done with ASP and an Access Database?
Thanks,
Jason
|
|
|
 |
|