dqrm8199 2017-02-02 08:34
浏览 27
已采纳

具有自己的会话实现的框架如何处理第三方?

I see quite some frameworks and CMS's that use their own session implementation instead of the native PHP session driver. All for their own reasons.

Examples of these are Wordpress, Laravel, CakePHP(somewhat).

What I am wondering is though, if they set a cookie manually and do session handling themselves how do they deal with thirdparty packages?

Thirdparty composer packages might interact with the default $_SESSION and might try and set session variables while $_SESSION is entirely not used.

Still with frameworks like Laravel from what I can remember it still interacts perfectly fine with thirdparty packages and they all get put into their own session implementation.

Would love to know from somebody who might have some experience with this.

edit

An example of a thirdparty package might be a php debugbar which can read from $_SESSION and insert it's own variable if needed. I know frameworks like Laravel have their own debugbar implementation for this that does not interact with the native $_SESSION.

I guess I want to know if it's viable to totally run your own $_SESSION implementation without having too much trouble.

  • 写回答

1条回答 默认 最新

  • duanmiyang6201 2017-02-02 10:18
    关注

    It might not be a perfect answer but here is at least what I found out from dealing with custom sessions implementations & the latest Laravel install.

    In Laravel 5.6 $_SESSIONglobal does not exist no session exists however when using the Session::all() it returns token of the session. This is logical.

    Route::get('/', function () {
       dump(Session::all());
       dd($_SESSION);
       return view('welcome');
    });
    

    Returns

    array:3 [▼
      "_token" => "G22ETumV1CQoolo2sAV0SA4wWmxFrZjTXTli7ico"
      "_previous" => array:1 [▼
        "url" => "http://127.0.0.1:8000"
      ]
      "_flash" => array:2 [▼
        "old" => []
        "new" => []
      ]
    ]
    

    And the dd

    ErrorException in web.php line 16:
    Undefined variable: _SESSION
    

    From my own testing my conclusion is if the composer package that interacts with Sessions does not implement a Laravel ServiceProvider it will not be able to do anything with session.

    Hope this is helpful response.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装