PHP authentication with multiple domains and subdomains
As far as I know, crossing sessions between sub-domains is fine, but it won't carry over to a whole new domain. To do that you need some sort of centralized data method, or an API.
Database method: you will have to create a remote MySQL data access so that domain2.com can access the database on domain1.com. When a log-in is performed, not only should it create a new session, but a unique log-in token (with an expiry time) should be put into the mysql database. Now, for every link that goes from domain1.com to domain2.com, you should add a $_GET variable that contains a randomly generated session id (md5 hash will do). domain2.com, upon receiving the visitor, will take the $_GET variable, run it through the MySQL database to find the login token, and if there is a match, consider that user to be logged on (and perhaps embed a $_COOKIE as well to store the login data). This will make the log-in transferrable between two completely different domains.
API method: you need to create an API method, so that domain1.com can respond to an external request from authorized domains to retrieve the login token upon a user being forwarded. This method will also require that all links going from domain1.com to domain2.com to be appended with a $_GET variable to pass the unique session hash. Then upon receiving the visitor, domain2.com will do a curl() request to domain1.com/userapi.php (or whatever you call the file) and the variables should be tested against what's in the database.
This is the best I can explain it.. to write this out in code is a significant piece of work so I cannot commit. But judging by your code, you have a very good understanding of PHP so I'm confident you will pull this off!
Good luck mate.
How to logon to multiple subdomains at once
login is based on cookie and session data . you need to set php session id(PHPSESSID) to set in a cookie with main domain.
you can login in main domain or set your cookie to access your domain and subdomains.
$currentCookieParams = session_get_cookie_params();
$rootDomain = '.example.com';
session_set_cookie_params(
$currentCookieParams["lifetime"],
$currentCookieParams["path"],
$rootDomain,
$currentCookieParams["secure"],
$currentCookieParams["httponly"]
);
session_name('mysessionname');
session_start();
setcookie($cookieName, $cookieValue, time() + 3600, '/', $rootDomain);
?>
Laravel login once and be loggined in in multiple subdomains
try this
in config/session.php
'domain' => env('SESSION_DOMAIN', null),
to
'domain' => env('SESSION_DOMAIN', '.mainwebsite.com'),
or in .env
SESSION_DOMAIN='.mainwebsite.com',
Related Topics
MySQL Alter Table Add Field Before or After a Field Already Present
Execute a PHP Script from Another PHP Script
I Have a Base64 Encoded Png, How to Write the Image to a File in PHP
Codeigniter - File Upload Required Validation
Codeigniter Assets Folder Best Practice
Arabic Characters in JSON Decoding
How to Convert Object into String in PHP
How to Select Rows Where Column Value Is Not Null Using Codeigniter's Activerecord
Difference Between Eloquent\Model::Get() and All()
Change Name of Laravel's Created_At and Updated_At
Php: Get List of All Filenames Contained Within My Images Directory
Regular Expression and Forward Slash
Regex, Get String Value Between Two Characters
Sql_Calc_Found_Rows/Found_Rows() Does Not Work in PHP
Dynamic Comparison Operators in PHP