0

I have two web Applications. I will login in to one Web Application and will navigate to another by links or redirection from the first Application. Lastly after completing some steps in Application two, I will be redirected to Application one. How can I implement this?

dev_info
  • 1
  • 1

2 Answers2

2

Create a new database called sessions.

Configure a connection profile for the session database secondary to your apps primary databases for both apps.

And then they should be syncing up in storing the data for sessions, being able to share them etc...

config/database.php

'app_main_database' => [
    'driver'    => env('DB_CONNECTION'),
    'host'      => env('DB_HOST'),
    'port'      => env('DB_PORT'),
    'database'  => env('DB_DATABASE'),
    'username'  => env('DB_USERNAME'),
    'password'  => env('DB_PASSWORD'),
],

'sessions_database' => [
    'driver'    => env('DB_CONNECTION_SESSION'),
    'host'      => env('DB_HOST_SESSION'),
    'port'      => env('DB_PORT_SESSION'),
    'database'  => env('DB_DATABASE_SESSION'),
    'username'  => env('DB_USERNAME_SESSION'),
    'password'  => env('DB_PASSWORD_SESSION'),
],

Configure session.connection to the name for your session driver

config/session.php

<?php

use Illuminate\Support\Str;

return [

    'driver' => env('SESSION_DRIVER', 'database'),

    'connection' => env('SESSION_CONNECTION', 'sessions_database'),
Tschallacka
  • 27,901
  • 14
  • 88
  • 133
0

Your question starts with "Laravel - How do..." which leads me to believe both of your applications are using Laravel. You said they are both on the same server and same domain so you could simply expand the default PHP Session cookie from the SLD (Second Level Domain) scope of yourdomain.com to be a cross subdomain cookie: *.yourdomain.com and then set the same application key and your applications will magically start using the and sharing the data. Just make sure that you did the right work in sharing the user database because Laravel default Auth will take the User ID column and log the user into the same ID.

Make sure the environment variables in the .env for both installations have the same identical settings:

#APP_KEY is used to encrypt the session data so must be the same
APP_KEY=base64:'YOUR KEY ' 
#SESSION_COOKIE must be the same, this is normally not set and defaults to APP_NAME+"_session' which is a problem if your apps have different names
SESSION_COOKIE=laravel_session
#The SESSION_DOMAIN defaults to null which causes the CORS scope to limit to the subdomain level, in my testing must start with leading dot.
SESSION_DOMAIN=.rootdomain.com
Neo
  • 11,078
  • 2
  • 68
  • 79