Function example for php to achieve multiple logon credits only once a day based on the login time judgment, php example

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.