duanlian1960 2018-03-13 19: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.

  • 写回答

1条回答 默认 最新

  • dongyutan1703 2018-03-13 20: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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部