首页 > 解决方案 > 检测会员时间到期PHP

问题描述

我正在尝试为一个月(2419200 秒)后在我的网站上购买会员资格的用户自动过期

但是,当我更改行的日期时,它似乎不起作用。我已经尝试将时间功能包装在不同的区域,甚至禁用它,我似乎遇到了它的工作问题。

buyDate 参数是我的 SQL 数据库中对象的一部分。(unix时间整数)任何帮助将不胜感激。

<?php       
if(time($membershipExpire->buyDate) <= time($membershipExpire->buyDate + 2419200)){
        die("Your membership has expired. Please contact someone to remove your membership in order to continue playing.");
    }
?>

标签: phpmysqlunixtime

解决方案


重写它略有不同

<?php
$end = $membershipExpire->buyDate + 2419200;
if(time() >= $end)
{
die("Your membership has expired. Please contact someone to remove your membership in order to continue playing.");
}
?>

我还注意到当前时间必须大于结束时间,而在您的原始代码中,您使用的是小于号。

还有一件事与代码无关。您的错误消息显示“您的会员资格已过期。请联系某人删除您的会员资格以继续玩。”

不应该是“更新您的会员资格”吗?


推荐阅读