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

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

报告相同问题?

悬赏问题

  • ¥15 cpuid是如何转换的
  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker
  • ¥15 Spring MVC项目,访问不到相应的控制器方法
  • ¥15 esp32在micropython环境下使用ssl/tls连接mqtt服务器出现以下报错Connected on 192.168.154.223发生意外错误: 5无法连接到 MQTT 代理,如何解决?
  • ¥15 关于#genesiscsheel#的问题,如何解决?
  • ¥15 Android aidl for hal
  • ¥15 STM32CubeIDE下载程序报错
  • ¥15 微信好友如何转变为会员系统?(相关搜索:小程序)
  • ¥15 c# 直接使用c++ 类库文件