Home  >  Article  >  Backend Development  >  活动给用户送金币

活动给用户送金币

WBOY
WBOYOriginal
2016-06-06 20:41:511195browse

php 怎么判断给用户一天送一次金币??

回复内容:

php 怎么判断给用户一天送一次金币??

session(判断用户)+数据库(当前时间是否落在上一次送金币时间决定的一天区间时间内=>当前时间是否大于上一次送金币时间决定的一天区间时间的上限,使用timestamp加加减减就好了)

如果不是非常严格 就用cookie呗 如果要严格 就建立个数据库字段 值为当天日期

在服务器端,记录送金币的时间戳,如果时间戳为当天就说明送过金币,不是就没送过。

<code>    $today = new DateTime('today');
    if(is_null($user->givedtime))
    {
        //一次都没送过
    }
    else if(strtotime($user->givedtime) >= $today->getTimestamp())
    {
        //当天送过
    }
    else {
        //当天没送过
    }
</code>
Statement:
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