菜单

Php based on landing time judgment to achieve multiple login once a day, only integral function examples

2017年11月23日 - PHPer

This paper describes the PHP based on landing time to achieve multiple login once a day, only integral function. To share with you for your reference, as follows:

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

This I added a logintime field in the data table, said the last login time, then use the day zero zero zero seconds and the last login time were compared, if the last login time is greater than the time point that has been landing, if login the last time is less than this point in time, said the first time login, increase integral

Upper code:

To determine whether it is the first time / day login

The last time / landing

$lastLogintime = $userinfo[‘logintime’];

/ / in a day zero zero zero seconds

$today = strtotime (date (‘Y-m-d’));

If ($lastLogintime < $today) {

The first time on the day / / integral (updating)

/ / Note: use related update data when you need to pass two times ID

$data[‘id’] = $userinfo[‘id’];

$data[‘userinfo’] = array

‘points’=> $userinfo[‘points’] + C (‘LOGIN’),

);

$user-> relation (true) -> where (array (‘id’=> $userinfo[‘id’])) -> save ($data);

}

It’s important to change the login time:

/ / update login time and login IP

$updateData = array

‘id’=> $userinfo[‘id’],

‘userinfo’=> array

‘logintime’=> time (),

‘loginip’=> getIP (),

),

);

$user-> relation (true) -> where (array (‘id’=> $userinfo[‘id’])) -> save ($updateData);

This makes it work

发表评论

电子邮件地址不会被公开。