代码之家  ›  专栏  ›  技术社区  ›  Jack B Nimble

cakephp-会话变量一直表现得很奇怪

  •  1
  • Jack B Nimble  · 技术社区  · 17 年前

    由于我无法理解的原因,包含客户姓名的会话变量将显示一段时间,然后消失。

    在app_controller.php中:before过滤器()

    if (isset($_SESSION['customer_name']) == false  || 
        strlen($_SESSION['customer_name']) == 0)
    {
      $customer = $this->Customer->read(null, $auth['User']['customer_id']);
      $name = $customer['Customer']['fname'] . " " . $customer['Customer']['lname'];
      $this->Session->write('customer_name', $name);
      $this->set('name', $this->Session->read('customer_name'));
    }
    else
    {
      $this->set('name', $this->Session->read('customer_name'));
    }
    

    if ($this->Session->check('customer_name') == false)
    

    6 回复  |  直到 17 年前
        1
  •  2
  •   Community Mohan Dere    6 年前

    使用 $this->Session->read() 而不是像cakephp那样直接调用$_SESSION,可以将会话存储在本地PHP所期望的其他地方。

    此外,我真的不明白你所说的“消失一段时间”是什么意思,如果你停留在同一页面上,只是不断点击刷新,它会随机显示/消失吗?

    你的是什么 Session.*

        2
  •  1
  •   devrys    13 年前

    if($this->Session->check('customer_name'))

        3
  •  0
  •   dr Hannibal Lecter    17 年前

    我不太确定问题是什么,但我会从删除$_SESSION调用开始。我也会改变

    strlen($_SESSION['customer_name']) == 0
    

    empty($_SESSION['customer_name'])
    

    我唯一能想到的另一件事是降低/config/core.php中的安全级别,也许你完全失去了会话?

        4
  •  0
  •   Jack B Nimble    17 年前

    $name = $customer['Customer']['fname'] . " " . $customer['Customer']['lname'];
    

    允许$name等于“”,这意味着它的strlen为1,并且不是空的。不知道为什么它没有得到客户数据,但现在我可以检查这个值。

        5
  •  0
  •   jimiyash    17 年前