简体   繁体   English

生成和过期优惠券代码/促销代码

[英]Generate & Expire coupon-codes/promo-codes

We are making a lottery website.我们正在制作一个彩票网站。 In which we want to generate some coupon-codes/promo-codes.我们要在其中生成一些优惠券代码/促销代码。 Is there any tried and tested code written which generates coupon-codes and expires them after exact 24hrs?是否有任何经过测试和测试的代码可以生成优惠券代码并在 24 小时后过期? We are using (PHP/mySQL).我们正在使用(PHP/mySQL)。

Thanks in advance.提前致谢。

There is.有。 It's called time() and is inside every single PHP distribution.它被称为time()并且在每个单独的 PHP 发行版中。

To expire a token, you need 2 steps:要使令牌过期,您需要两个步骤:

  • On creating the coupon you call time() which generates an integer and add the number of seconds you want the token to be valid to it, then store the result in an unsigned int field called expires在创建优惠券时,您调用time()生成一个整数并添加您希望令牌有效的秒数,然后将结果存储在名为expires的无符号 int 字段中
  • On checking a token you compare this stored value with the current output of time() - if the latter is bigger the coupon has expired.在检查令牌时,将此存储值与time()的当前输出进行比较 - 如果后者较大,则优惠券已过期。

You can clean up expired tokens with DELETE FROM tablename WHERE expires<UNIX_TIMESTAMP() , but I would not recommend going this route naively, as it will rob you the possibility to differentiate between an expired and an inexistant token.您可以使用DELETE FROM tablename WHERE expires<UNIX_TIMESTAMP()清理过期的令牌,但我不建议天真地走这条路,因为它会剥夺您区分过期令牌和不存在令牌的可能性。

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

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