如何在php中检索比较时间的数据


how to retrieve data on compare time in php

我的代码:

$query =    "INSERT IGNORE INTO `user_app` (app_id,imei, package_name, sdk_name, sdk_version, app_version)
                VALUES 
                ('".$appid."','".$imei."', '".$pkg."', '".$sdkn."', '".$sdkv."', '".$appv."')"; 
    $mysqli -> query($query);
    $id = $mysqli -> insert_id ; //get last user insert id
    $idt = date('G:i:s', time());
    $new = strtotime($idt);
    include('requestad.php');

当一个新用户注册时,他将从requestad.php获得一个json格式的广告。Insert id保存在一个名为$id的单独变量中,如果用户再次通过应用程序点击(每30分钟调用一次应用程序),那么他将再次获得json广告。我正在尝试做一些事情,比如用户在整个24小时内只获得一次广告,这可以通过Insert id和Insert时间戳实现。我正在做这样的事情:

if ( $new == time() ) {
        include('requestad.php');
    } elseif ( $new < time() ) {
            echo 'nothing';
    } 

但问题是,我并没有在变量中保存确切的执行时间,保存时间是比较所必需的。此外,如果用户再次请求资源,我必须向他发送一些空白。请看一下,并帮助我生成最佳解决方案。不过我还没有运用任何逻辑。我可以通过静态的存储时间来实现这一点,并将其与显示实时的时间()进行比较。我仍然在看这个

$store_time=$row['time'];//pick up the store time of user 
$store_time=strtotime($row['time']);//and convert it in strtotime.if alredy did no need to do this.
$new=strtotime("-24 hours",strtotime(time()));//substract the time to -24 hours.
if($new==$store_time)
{
//your code
}
else
{
//your code
}