dqdjfb2325 2017-04-23 19:44
浏览 22

Fat Free框架PHP - 基于变量创建不同的会话

I am trying to create a session for user and another for admin based on a variable which gets the status (from database) of the username. I have managed to create a session for user but it doesn't seem to work for admin. I get an error Undefined index: user, when I try to login as admin and I dont know whats causing the problem.

How do I create a different session for admin?

This is the code written in the controller:

        $user = new Login($this->db);
        $user->getByName($username);

        if ($s['status'] == 'user'){
        $this->f3->set('SESSION.user', $user->username);
        $this->f3->reroute('/');
    }


        if ($s['status'] == 'admin'){

        $this->f3->set('SESSION.admin', $user->username);
        $this->f3->reroute('/');
    }
  • 写回答

1条回答 默认 最新

  • donglong2856 2017-04-24 14:10
    关注

    I guess, the status variable can have only one value at a time, in that case you need to have an else in the if condition

    if ($s['status'] == 'user'){
       $this->f3->set('SESSION.user', $user->username);
       $this->f3->reroute('/');
    } else if ($s['status'] == 'admin'){
       $this->f3->set('SESSION.admin', $user->username);
       $this->f3->reroute('/');
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本