• 0

Help on consecutive days logged in


Question

Hi,
 
It is relatively simple but I am making it complicated.
 
I want a counter on a player's profile of how many consecutive days they have been active.
 
Logged in 51 days consecutively
Longest consecutive period was 68 days
 
I'm not sure how to store and check.
 
1. I store their latest online time UNIX every time they refresh the page.
2. Need a function that would update the counter if it has not been updated already that day.
 
My thoughts are:
Could run a Cron every 24 hours to simply check if their online has been within the last day then either reset or +1. Also check if current consecutive is larger than consecutive record if so copy over.
 
How would you do it?

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

I'd store 2 values: Count and Last Online.

If last online == today -1, count++;

else if last online != today, count = 0;

last online = today/now/whatever;

Run that as a cron and you should be right, alternatively on login or pageload depending on how things are running.

Link to comment
Share on other sites

This topic is now closed to further replies.