0

我正在使用 Zend MVC 项目。我的任务:添加只有用户唯一 ID 的 cookie。

问题:我不知道在哪里创建 cookie。

放置创建cookie的选项,我关心的是:

  1. bootstrap.php 初始化()/运行()

  2. index.php(没有意义)

  3. 在控制器中

我的项目结构

应用程序/bootstrap.php

公共/index.php


请帮助我,如果你能举个例子,那就太好了。

谢谢,约瑟夫

4

1 回答 1

0

I've put it in the Bootstrup.php, I just created new method called _initUserUniqueId:

protected function _initUserUniqueId(){

    $uniq = uniqid();
    if(!isset($_COOKIE['f_uniq'])){ 
        setcookie('f_uniq', $uniq, time() + 60 * 60 * 24 * 365, '/');
    }
}
于 2011-07-21T03:33:41.263 回答