繁体   English   中英

检查用户订阅是否有效-不起作用

[英]Check If User Subscription Is In Date - Not Working

目前,我的登录脚本中包含以下代码,以检查用户订阅是否有效:

// get the current date
$now = date("Y-m-d");
    if ($user_id['enddate'] < $now) {
      ?>
      <p>your Licence is out of date</p>
      <?php
      }
else
      {
      ?>
      <p>your licence is in date</p>
      <?php
      }

存储到期日期的值为“ enddate”。

无论用户是否已订阅,它都直接指向过期消息。 我无法解决这个问题。

enddate的MYSQL字段只是类型“ date”,它是从注册脚本生成的:

$enddate = date("Y-m-d", strtotime("+ 365 day"));

有任何想法吗? 我知道我正在使用折旧的MYSQL,但是我需要进行此项目。

干杯

您需要转换为时间,日期只是一个字符串...

$now = strtotime(date("Y-m-d"));
if (strtotime($user_id['enddate']) < $now) {
  ?>
  <p>your Licence is out of date</p>
  <?php
  }
else
  {
  ?>
  <p>your licence is in date</p>
  <?php
  }

仅供参考:解决了以下问题:

$expirydate = mysql_query("SELECT enddate FROM users WHERE user_id = '".$_SESSION["user_id"]."'"); echo $query;
$expirydate2 = mysql_result($end, 0);
$now = strtotime(date("Y-m-d"));
if (strtotime($expirydate2) < $now) {

希望这对某些人有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM