Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Counter Needed

Status
Not open for further replies.

aleci

Programmer
May 22, 2001
40
GB
Hi all,
I want to be able to tell a visitor to a certain page that s/he has logged in x number of times.

People log in with a username/password combination passed through form fields , which is verified against information stored in a DB, before each user session is initialized:

<CFQUERY NAME=&quot;security_check&quot; DATASOURCE=&quot;#db#&quot;>
SELECT passwords.user_id,
passwords.password,
passwords.user_name
FROM passwords
WHERE passwords.user_id = '#form.user_id#' AND
passwords.password = '#form.password#'
</CFQUERY>

Any help with setting up a session counter to distinguish individual users will be hugely appreciated!
Thanks
 
Hey Aleci,

There are several ways you could do something like this. I would recommend adding a loginCount field in your passwords table and set it to be a numeric field. You'll then want to run a query to set all values to 0.

updates passwords set loginCount = 0

I would then change your login query to this:

<CFQUERY NAME=&quot;security_check&quot; DATASOURCE=&quot;#db#&quot;>
SELECT passwords.user_id,
passwords.password,
passwords.user_name

,passwords.LOGINCOUNT <!--- added this line --->

FROM passwords
WHERE passwords.user_id = '#form.user_id#' AND
passwords.password = '#form.password#'
</CFQUERY>

Then, after someone has successfully logged in, I would do this:

<cfset x = security_check.loginCount + 1>

<cfquery ....
updates passwords
set loginCount = #x#

WHERE passwords.user_id = '#form.user_id#' AND
passwords.password = '#form.password#'

Then you can display the message as &quot;You have now logged in #x# times.&quot;

Hope this helps,
GJ
 
You may also be interested in this tag:

CF_TrackMan

It will track and record what page (or directory) each user is on. You can then display (or record) all the people that are currently &quot;online&quot;.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top