douzhan2027 2015-12-03 13:30
浏览 71
已采纳

CakePhp 3.x从应用程序中继续会话

I'm building a new version of a website in cakephp 3.x. Since I rebuild in phases,I need interaction between parts of the new site and the old site. The best way to do this at this moment is with the use of $_SESSION. My problem is that the cakephp part makes a new session instead of using the active one from the native PHP part. It writes it next to it in the same folder.

this is my app.php setting in cakephp

 'Session' => [
    'defaults' => 'php',
    'timeout' => '2000',
 'ini' => [
     'session.cookie_domain' => '.domain.com',
     'session.save_path' => '/var/www/clients/web/tmp',
     'session.name' => 'PHPSESSID'
 ]
],

These are my php.ini settings

Session Support enabled
Registered save handlers    files user memcache memcached
Registered serializer handlers  php php_binary wddx

Directive   Local Value Master Value
session.auto_start  Off Off
session.cache_expire    180 180
session.cache_limiter   nocache nocache
session.cookie_domain   no value    no value
session.cookie_httponly Off Off
session.cookie_lifetime 0   0
session.cookie_path /   /
session.cookie_secure   Off Off
session.entropy_file    /dev/urandom    /dev/urandom
session.entropy_length  32  32
session.gc_divisor  1000    1000
session.gc_maxlifetime  1440    1440
session.gc_probability  0   0
session.hash_bits_per_character 5   5
session.hash_function   0   0
session.name    PHPSESSID   PHPSESSID
session.referer_check   no value    no value
session.save_handler    files   files
session.save_path   /var/www/clients/web/tmp    /var/www/clients/web/tmp
session.serialize_handler   php php
session.upload_progress.cleanup On  On
session.upload_progress.enabled On  On
session.upload_progress.freq    1%  1%
session.upload_progress.min_freq    1   1
session.upload_progress.name    PHP_SESSION_UPLOAD_PROGRESS PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix  upload_progress_    upload_progress_
session.use_cookies On  On
session.use_only_cookies    On  On
session.use_trans_sid   0   0
  • 写回答

1条回答 默认 最新

  • douchen9569 2015-12-03 14:25
    关注

    The session.name ini option gets overwritten by the session configs cookie option if it is set (which it will be by default in case the defaults option is is set).

    By default the session class instance is being created via Session::create(), consuming your session configuration, and then inheriting the corresponding CakePHP session defaults in case the defaults optin is being used. All of the available defaults do define the cookie option, which has a value of CAKEPHP. The php defaults currently looks like

    'cookie' => 'CAKEPHP',
    'ini' => [
        'session.use_trans_sid' => 0,
    ]
    

    https://github.com/cakephp/cakephp/blob/3.1.5/src/Network/Session.php#L131-L136

    The cookie option, when present, will overwrite the session.name ini option in the session class' constructor, and thus your PHPSESSID setting gets lost, and consequently the existing session is not going to be picked up.

    tl;dr - Use the cookie option, or do not inherit defaults

    So, you could either use the cookie option instead of session.name

    'Session' => [
        'defaults' => 'php',
        'cookie' => 'PHPSESSID',
        'timeout' => '2000',
        'ini' => [
            'session.cookie_domain' => '.domain.com',
            'session.save_path' => '/var/www/clients/web/tmp'
        ]
    ],
    

    or do not inherit the defaults, and define everything necessary on your own

    'Session' => [
        'timeout' => '2000',
        'ini' => [
            'session.cookie_domain' => '.domain.com',
            'session.save_path' => '/var/www/clients/web/tmp',
            'session.name' => 'PHPSESSID',
            'session.use_trans_sid' => 0
        ]
    ],
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵