What is needed is a possibility to transfer a session between 2 different domains.
In order to achieve that, you need to do following (this is one of the options):
- Create a method named
setcookie
on example-B.com
and example-C.com
, which can retrive a token and write user a session cookie.
- In the
login
method in example-A.com
: Use curl
to login in example-B.com
. - I assume you have login controllers on your all 3 sites, and since the usage of curl is off topic, I'm not gonna to paste the code here, I'm sure you can handle that :)
- After a success login, get the session cookie from
example-B.com
.
- Show the logined user a
<img>
like <img src="http://example-B.com/setcookie?token=xxxx" style="display: none;" />
to write the session cookie to the admin user.
- Now the logined session has been transfered from
curl
to the user, he can now access example-B.com
as a logined user.
EDIT: Sorry I don't use laravel very often :( I use a framework called ThinkPHP, its fashion in china, the syntax is similar to laravel, hope I can help you
For security reason, you can't set cookies for other domains, but you can get to the other domain and set a cookie for the user.
step 1 code:
Add a new controller and write a function in it:
public function setcookie($token = '') {
// the $token here is the $_GET['token'] parameter filtered by the framework
if(!empty($token) && strlen($token) > 0) { // check if the param is not empty...
setcookie("PHPSESSID", $token, 0, '/', '', false, true); // this will set a cookie for anyone who visited this action
}
}
So the curl
logged in the user and got a session id, then the dashboard page shows user a hidden <img src="setcookie?token=xxx">
to set the user a session cookie with the session id curl
got, then the user can visit the other site as a logged in user.