简体   繁体   中英

How to modify expiry date in PHP?

I'm creating a system for controlling my users purchase. I'm saving date like this in my SQL: dmY 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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