Graeme McGilvray
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?
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?
ASKER
Thanks for that Scott,
However I am after the counter part, as I already have the code for the date.
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.
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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window