Link to home
Start Free TrialLog in
Avatar of Graeme McGilvray
Graeme McGilvrayFlag for Australia

asked on

Creating a visitor counter without a database

Hi there, I want to create a counter for my website that is unique for cookies...

I am unsure on how to do this, so I will need some guidence...

My Idea of a cookieID would prefer to be...

20190718-1
the date in reverse and then the order of the visitor of the day, first visitor gets number 1, second number 2, etc.

How would I be able to create the counter without a database?
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

year = year(now)
theMonth = month(now)
theMonth = Right("0" & cstr(theMonth ) , 2) ' adds leading zero
theDay = day(now)
theDay = Right("0" & cstr(theDay ) , 2) ' adds leading zero
theMinute = Minute(now)
theMinute = Right("0" & cstr(theMinute ) , 2) ' adds leading zero
theSecond = second(now)
theSecond = Right("0" & cstr(theSecond  ) , 2) ' adds leading zero

timeStamp= year&theMonth &theDay&theMinute&theSecond

Open in new window

Avatar of Graeme McGilvray

ASKER

Thanks for that Scott,

However I am after the counter part, as I already have the code for the date.
You don't need a counter if you are using minutes and seconds.

Otherwise, you can create a table in the database with an auto number and insert a new record and grab the number. Or a table that has a timestamp with a default value of  GETDATE() and and int field. If the timestamp is <= 23:59 than add 1 to the last inserted record.  

You could do the same thing with a text file on the server where you write the number 1, then the next time you add 1 to that to get 2 and so on.  I think using the db will be easier to manage especially when there are multiple hits at the same time.
I ended up canning this idea and went with a autonumber that is generated in the database.
I think that is the best choice
ASKER CERTIFIED SOLUTION
Avatar of Graeme McGilvray
Graeme McGilvray
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial