创建特定时期的折扣系统

时间:2014-04-26 09:41:09

标签: php codeigniter e-commerce

我使用CodeIgniter,我想在有限的时间内提供折扣。我不知道如何编码,会话会好吗?但是,如果我只需要前15分钟,我该怎么办呢?

2 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

您可能需要略微更改逻辑才能使其正常工作。

<?php
    function discount_period($field,$time)
    {
        $t = time();
        $t0 = $_SESSION[$field];
        $diff = $t - $t0;
        if ($time > 1500 || !isset($t0))
        {          
            return true;
        }
        else
        {
            $_SESSION[$field] = time();
        }
    }

    /* Inside your header */

    if(discount_period("user_time",1500))
    {
        session_unset();
        session_destroy();
        location("some-other-page.php");          
        exit;
    }    
?>

答案 1 :(得分:0)

我不知道你会怎么做,但你可以使用这段代码作为参考。

<?php

$userLoggedInDate = new DateTime('now'); //The time user logged in. You can store it in the session variable the first time the user had logged in.

$promoDate = 'April 26, 2014';
$date = new DateTime($promoDate); //promo start date
$date2 = new DateTime($promoDate.'+15 min'); //add 15 mins to the date

var_dump($userLoggedInDate>$date2); //is logged in date greater than the promo end time? 
var_dump($userLoggedInDate<$date2); //is logged in date less than the promo end time?