Function example for php to achieve multiple logon credits only once a day based on the login time judgment, php example
The example in this article describes how to use php to perform multiple logon credits once a day based on the logon time judgment. We will share this with you for your reference. The details are as follows:
I have found many cases on the internet, and I feel like they are all the same. Some of them are complicated. I tried it myself and how to implement this function.
To implement this function, I added a logintime field to the data table to indicate the last logon time. Then, I compared the Last Logon Time With 00:00:00 in a day, if the last logon time is later than this time point, it indicates that you have logged on. If the Last Logon Time is earlier than this time point, it indicates the first logon, adding points.
Code:
// Determine whether it is the first logon time in a day. // The Last Logon Time $ lastLogintime = $ userinfo ['logintime']; // 00:00:00 in a day $ today = strtotime (date ('Y-m-d'); if ($ lastLogintime <$ today) {// Add points (associated update) for the first logon in a day // note: the id $ data ['id'] = $ userinfo ['id'] must be passed twice when data is updated by association. $ data ['userinfo'] = array ('points' => $ userinfo ['points'] + C ('login'),); $ user-> relation (true) -> where (array ('id' => $ userinfo ['id'])-> save ($ data );}
You must also modify the logon time:
// Update the logon time and logon ip address $ updateData = array ('id' => $ userinfo ['id'], 'userinfo' => array ('logintime' => time (), 'loginip' => getIP (),),); $ user-> relation (true) -> where (array ('id' => $ userinfo ['id'])-> save ($ updateData );
In this way, this function is implemented.