An example of php realizing the function of logging in multiple times a day and integrating only once based on logging time judgment

  • 2021-08-12 02:11:52
  • OfStack

In this paper, an example is given to describe the function that php can only score once for multiple logins in one day based on the judgment of login time. Share it for your reference, as follows:

Looking for a lot of cases on the Internet, the feeling is almost the same, and some are more tedious, on their own try 1, how to achieve this function

To realize this function, I added a field logintime in the data table. Indicates the last login time, and then compares it with the last login time by 0: 00:0: 00sec in one day. If the last login time is longer than this time point, it indicates that you have logged in. If the last login time is less than this time point, it indicates the first login, and increases points

On the code:


//  Determine whether it is 1 Tianzhongdi 1 Secondary login 
//  Upper 1 Time of the first landing 
$lastLogintime = $userinfo['logintime'];
// 1 Zero hours and minutes in the sky 
$today = strtotime(date('Y-m-d'));
if($lastLogintime < $today) {
  // 1 Tianzhongdi 1 Increase points for secondary login ( Association update )
  //  Note: When using association to update data, you need to pass it twice id
  $data['id'] = $userinfo['id'];
  $data['userinfo'] = array(
    'points' => $userinfo['points'] + C('LOGIN'),
  );
  $user->relation(true)->where(array('id'=>$userinfo['id']))->save($data);
}

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


//  Update logon time and logon ip
$updateData = array(
  'id' => $userinfo['id'],
  'userinfo' => array(
    'logintime' => time(),
    'loginip' => getIP(),
  ),
);
$user->relation(true)->where(array('id'=>$userinfo['id']))->save($updateData);

This enables this function

For more readers interested in PHP related contents, please check the topics on this site: "Summary of php Date and Time Usage", "Encyclopedia of PHP Array (Array) Operation Skills", "Introduction to php Object-Oriented Programming", "Introduction to php String (string) Usage", "Introduction to php+mysql Database Operation" and "Summary of Common Database Operation Skills of php"

I hope this article is helpful to everyone's PHP programming.


Related articles: