Maintain the same session for two laravel projects in subdomains

1

I would like to create two laravel projects in two subdomains on the same server,

eg:

  • app1.domain.com
  • app2.domain.com

It would be with the same database, what I would like is that when logging in to an application, it will also be logged if you enter in the other application.

How could I do this with Laravel 5.4?

    
asked by Leoh 28.07.2017 в 15:57
source

3 answers

1

There are several ways to solve this, depending on the details of each scenario, but perhaps the most common way is to modify the domain in config.php:

app / config.php

domain => '.dominio.com'

After this, you must clean the cookies previously stored for those sites.

Another way, maybe less orthodox but equally simple in case you have only one instance of Laravel for the two subdomains, is to simply direct both public/index.php files to the same instance, something like this:

In the content of both files, replace the following two lines to the same instance of Laravel, or in other words to the same directory bootstrap :

app1.domain.com/index.php and app2.domain.com/index.php

// Línea 22
require __DIR__.'/../bootstrap/autoload.php';

// Línea 36
$app = require_once __DIR__.'/../bootstrap/app.php';
    
answered by 29.07.2017 в 16:45
0

I think the sessions are unique to a specific domain. I'm still looking for PHP documentation where I talk about that ...

I would recommend you use another strategy to do this.

such as tokens that you can exchange between domains.

    
answered by 29.07.2017 в 03:56
0

Authentication system using tokens on various platforms laravel

Prerequisites:

  • Api or feed system using HTTP GET | POST
  • fluid management of web storage of HTML5

For the logins you want to unify you have to add a web storage .

When you start a session in your application, you save the token which must be in the same way in a DB in the web sotrage.

  

This is for the purpose of comparing the client's token with the DB token.

Then, when you are in the login of your applications look for this variable with JS and send it via AJAX to the server, if this Token is valid you only do the corresponding redirection and in that redirection you save your session data you need.

  

In this redirection you can send the token again, so you can search for the owner, and upload the data you need to the session ...

This is more or less equal Remember me

I hope I help you, if you have questions. I'm glad to help you ...

    
answered by 04.08.2017 в 00:37