简体   繁体   English

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

[英]CakePhp 3.x Continue session from out of the app

I'm building a new version of a website in cakephp 3.x . 我正在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 . 目前最好的方法是使用$ _SESSION My problem is that the cakephp part makes a new session instead of using the active one from the native PHP part. 我的问题是,cakephp部分将进行一个新会话,而不是使用本机PHP部分中的活动会话。 It writes it next to it in the same folder. 它将它写在同一文件夹中。

this is my app.php setting in cakephp 这是我在cakephp中的app.php设置

 '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 这些是我的php.ini设置

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

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). 如果设置了session.name ini选项,则会被session configs cookie选项覆盖(如果设置了defaults选项,默认情况下将被覆盖)。

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. 默认情况下,会话类实例是通过Session::create() ,使用会话配置,如果使用defaults optin,则继承相应的CakePHP会话默认defaults All of the available defaults do define the cookie option, which has a value of CAKEPHP . 所有可用的默认值都定义cookie选项,其值为CAKEPHP The php defaults currently looks like php默认值目前看起来像

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

https://github.com/cakephp/cakephp/blob/3.1.5/src/Network/Session.php#L131-L136 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. cookie选项(如果存在)将覆盖会话类的构造函数中session.name ini选项,因此您的PHPSESSID设置将丢失,因此现有会话将不被使用。

tl;dr - Use the cookie option, or do not inherit defaults tl; dr-使用cookie选项,或者不继承默认值

So, you could either use the cookie option instead of session.name 因此,您可以使用cookie选项代替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
    ]
],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM