dpwqicw157673 2017-10-05 15:47
浏览 40
已采纳

如何在常规PHP脚本中继续CakePHP 3会话?

My situation is the following. I have a cakephp project and a seperated plain php script running on the same server. When I use my client browser to connect to the cakephp project, it builds up a session as it should.

Now I want to continue the session data with my plain php script. Again I use the same client browser to access the plain php script (so the request meta data should be the same and the session should be recognized) and I set cakephp session option to PHP.

'Session' => [
  'defaults' => 'php',
 ],

However, I cant find out how to continue the session on the plain php script. I would have assumed the following two lines of my plain php script would do the magic:

session_start(); 
echo json_encode($_SESSION);

Kind regards, Marius

  • 写回答

1条回答 默认 最新

  • dongzhi5846 2017-10-05 16:31
    关注

    CakePHPs PHP session defaults (like all built-in defaults) do change the name of the cookie / the name of the session (session.name INI setting) to CAKEPHP:

    https://github.com/cakephp/cakephp/blob/3.5.3/src/Network/Session.php#L133-L138

    So you either have to change that to match the defaults used by your vanilla PHP app (which is most probably PHPSESSID, ie the PHP default):

    'Session' => [
        'defaults' => 'php',
        'cookie' => session_name(), // would use the PHP default
    ],
    // ...
    

    or change the latter app to use the name configured for your CakePHP application:

    session_name('CAKEPHP');
    session_start();
    // ...
    

    Also make sure that the session.cookie_path and session.cookie_domain configuration covers both of your applications locations.

    See also

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

报告相同问题?

悬赏问题

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