2 Laravel apps, only one can login

前提是你 提交于 2019-12-11 13:11:41

问题


I'm creating a web app and I need to deploy it as multiple web app instance Let's say I'm deploying app as

root    
  |_ app1
  |_ app2
  |_ app3

Both app2 dan app3 are cloned from app1 via git. After that I do composer install and let them installs..

everything went fine when I log in to app1, but after logging in to app2, My app1 login was logged-out without clear reason. My first verdict was the session colliding, but I don't find any lead changing Laravel session key... So I tried changing the App Key but it doesn't do anything.

Anyone can point me some lead or answer? Thank you

P.S: I access the via subfolder (eg: http://mydomain/app1, http://mydomain/app2, http://mydomain/app3 )


Things I've tried:

  • changing App Key
  • changing session.cookie and assign different names to each site

Edit: changing session.cookie and assign different names to each site is the correct solution


回答1:


For security reasons, your session will be terminated, given that they are all stored in the same table.

Basically, you need to have a different config for each of your multisite.

Go to app/bootstrap/start.php

Replace this:

$env = $app->detectEnvironment(array(
   'local' => array('homestead'),
));

With this(example):

$env = $app->detectEnvironment([
    "app1"   => ["app1.mysite.com"],
    "app2" => ["app2.mysite.com"]
]);

Then in your app\config folder, create two new folders app1 and app2.

Whatever config files you place in them, will be loaded when the respective websites are visited.

If a config file is not present, the global default will be loaded.

Lastly, no need to have a different app folder for each website, unless you want a clear separation of concerns.

Read more about multisites




回答2:


Changing session.cookie is the correct solution!

Start creating session.php on config and put different values for cookie for each app

<?php
return [
    'cookie' => 'app1'
];

<?php
return [
    'cookie' => 'app2'
];

after that CLEAR YOUR BROWSER'S COOKIE! (This is important!) Without clearing, your last login behaviour will still conflict and the show can't go on.

That's it! You can have multiple Laravel site which is duplicated from one another on different subfolders.



来源:https://stackoverflow.com/questions/28299404/2-laravel-apps-only-one-can-login

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