PHP implements the function of only scoring once for multiple logins a day based on the login time judgment.

不言
Release: 2023-03-25 08:20:02
Original
1233 people have browsed it

This article mainly introduces the function of php based on login time judgment to achieve only one point for multiple logins a day. It is suitable for the points function of the membership system. It involves php time judgment and database related operation skills. Friends in need can refer to it

The example in this article describes how PHP can achieve only one point for multiple logins a day based on login time judgment. I would like to share it with you for your reference. The details are as follows:

I found a lot of cases on the Internet, and they all seemed similar. Some of them were quite complicated, so I tried it myself and how to implement this function.

To implement this function, I added a field logintime to the data table, indicating the last login time, and then compared it with the last login time using 0:00:00 of the day. If the last login time is greater than This time point indicates that you have logged in. If the last login time is less than this time point, it means you have logged in for the first time and points will be increased.

Code:

// 判断是否是一天中第一次登录
// 上一次登陆的时间
$lastLogintime = $userinfo['logintime'];
// 一天中的零时零分零秒
$today = strtotime(date('Y-m-d'));
if($lastLogintime < $today) {
  // 一天中第一次登录增加积分(关联更新)
  // 注意:使用关联更新数据的时候需要传递两次id
  $data[&#39;id&#39;] = $userinfo[&#39;id&#39;];
  $data[&#39;userinfo&#39;] = array(
    &#39;points&#39; => $userinfo[&#39;points&#39;] + C(&#39;LOGIN&#39;),
  );
  $user->relation(true)->where(array(&#39;id&#39;=>$userinfo[&#39;id&#39;]))->save($data);
}
Copy after login

It should be noted that the login time must also be modified:

// 更新登录时间和登录ip
$updateData = array(
  &#39;id&#39; => $userinfo[&#39;id&#39;],
  &#39;userinfo&#39; => array(
    &#39;logintime&#39; => time(),
    &#39;loginip&#39; => getIP(),
  ),
);
$user->relation(true)->where(array(&#39;id&#39;=>$userinfo[&#39;id&#39;]))->save($updateData);
Copy after login

This way this function is implemented

Related recommendations :

Detailed explanation of PHP stack-based implementation of advanced calculator functions

##

The above is the detailed content of PHP implements the function of only scoring once for multiple logins a day based on the login time judgment.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!