duanlian1960
duanlian1960
2018-03-14 03:02
浏览 19
已采纳

如何在PHP中修改失效日期?

I'm creating a system for controlling my users purchase. I'm saving date like this in my SQL: d.m.Y H:i I want to add expired date after 1 - 3 and 7 days. Example:

Creating date: 14.03.2018 05:54 End date: 17.03.2018 05:54

I want to add this days (1-3-7) after the first date automatically. I tired many codes from stackoverflow but it's doesn't work.

Thanks.

图片转代码服务由CSDN问答提供 功能建议

我正在创建一个用于控制用户购买的系统。 我在我的SQL中保存这样的日期: d.m.Y H:我我想在1到3天和7天之后添加过期日期。 示例:

创建日期: 14.03.2018 05:54 结束日期: 17.03.2018 05:54

我想在第一个日期后自动添加这几天(1-3-7)。 我厌倦了stackoverflow中的许多代码,但它不起作用。

谢谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyutan1703
    dongyutan1703 2018-03-14 04:12
    已采纳

    you can create expire php file for example: expire.php

    <?php
        $day1 = Date("Y/F/j",strtotime("-1 days");
        $day2 = Date("Y/F/j",strtotime("-3 days");
        $day3 = Date("Y/F/j",strtotime("-7 days");
       /* You just have to create a condition in your own loop
        for example: */
        $query=mysql_query("select * from user");
        while ($row=mysql_fetch_array($query)){
        if($row['date']>=$day1){
        $id=$row['id'];
        @mysql_query("update user set expire='1' WHERE id='$id'");
        echo "expire";
        }
        }
    ?>
    

    after that you should create Cron Jobs in your cpanel or directadmin for expire.php

    点赞 评论

相关推荐