public static function createToken ($name = 'csrfToken', $validTime = null)
    {
        if (! is_int($validTime))
            $validTime = 60 * 60 * 24; // token is valid for 1 day

        $csrfToken = Http::getInstance()->session()->get($name, null);
        $storeTime = Http::getInstance()->session()->get($name . 'Time', 0);

        if ((($validTime + $storeTime) <= time()) || empty($csrfToken)) {
            // Generate new csrf token.
            Http::getInstance()->session()->set($name, self::generateToken());
            Http::getInstance()->session()->set($name . 'Time', time());
        }

        return Http::getInstance()->session()->get('csrfToken');
    }