You should add a consecutiveDayCounter
and a lastDayConnected
row in your user table.
In your SELECT
query to check if the user and password matches, you should also SELECT these row.
Verify if lastDayConnected == than yesterday timestamp.
Then, do an UPDATE
query with today timestamp for the lastDayConnected
, and if the check for lastDayConnected == yesterday timestamp, add +1 to consecutiveDayCounter
. If not, update it to 0.
EDIT :
As asked, here's some example code to get today - yesterday stamp :
<?php
// Today
$today = new DateTime(); // Create new date object (today date)
echo $today->format('Y-m-d'); // Format the date 'YYYY-MM-DD'
// Yesterday
$yesterday = new DateTime(); // Create new date object (today date)
$yesterday->sub(new DateInterval('P1D')); // Substract 1 day to it
echo $yesterday->format('Y-m-d'); //Format the date 'YYYY-MM-DD'
?>