【问题标题】:Laravel with subdomain losing sessions on redirectLaravel 子域在重定向时丢失会话
【发布时间】:2016-05-01 14:56:22
【问题描述】:

我使用子域通配符来创建用户特定页面,例如 {slug}.mysite.com

用户可能会从 mysite.com 导航到 {slug}.mysite.com

但是我似乎对这两个路由/域有不同的登录会话。

Route::group(['domain' => '{slug}.mysite.com'], function()
{
    Route::get('/', 'PagesController@showByUsername');

    Route::get('/plans/{plan}', 'PlansController@showslug');

    Route::controllers([
        'auth' => 'Auth\AuthControllerClient'
    ]);
});

【问题讨论】:

    标签: php laravel subdomain


    【解决方案1】:

    这是因为 cookie 是特定于子域​​的。

    这是来自 config/session.php

    /*
    |--------------------------------------------------------------------------
    | Session Cookie Domain
    |--------------------------------------------------------------------------
    |
    | Here you may change the domain of the cookie used to identify a session
    | in your application. This will determine which domains the cookie is
    | available to in your application. A sensible default has been set.
    |
    */
    
    'domain' => null,
    

    您需要将此值设置为包含所有子域的值。

    https://serverfault.com/questions/153409/can-subdomain-example-com-set-a-cookie-that-can-be-read-by-example-com

    【讨论】:

    • 所以我可以设置 'domain' => 'mysite' 如果模式总是 {slug}.mysite.com ?
    • 请阅读我给你的那个链接,它引用了详细说明 cookie 工作原理的 RFC。它比我更清楚,但我相信域需要是 .mysite.com - 注意包含它的点是通配符。
    • 如果我有 .mysite.com,daulft 站点 (mysite.com) 是否也包括在内? (不带 www)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    相关资源
    最近更新 更多