Session conflicts with multiple Laravel projects on one server

心不动则不痛 提交于 2019-12-24 11:28:35

问题


I have a shared server for several Laravel projects. Example:

x.x.x.x/project1
x.x.x.x/project2

My problem is that when I try to login in project1, project2 will automatically logout. Is it because of Laravel sessions?

Could someone suggest what I should do?


回答1:


The path of the session cookie is configurable. Take a look at the path key in config/session.php




回答2:


This is not a session issue, but a cookie issue. You can fix APP_NAME in your .env file differently for each project.

This is because of the cookie configuration part of the session.php file.

'cookie' => env(
    'SESSION_COOKIE',
    Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
),



回答3:


I changed the session cookie identifier to add the environment, so I could have a dev and live site open in the same browser at the same time. Here is the code I replaced in config/session.php for the cookie:

'cookie' => env(
    'SESSION_COOKIE',
    str_slug(env('APP_NAME', 'laravel'), '_').env('APP_ENV','dev').'_session'
),


来源:https://stackoverflow.com/questions/32647464/session-conflicts-with-multiple-laravel-projects-on-one-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!