Hi, In this tutorial I am going to explain how to make cross domain session in laravel .
In my previous tutorial i have explained how to make cross domain request using jquery ajax. Use Same ajax concept in laravel also.
One thing you need to follow for laravel.
Add your header in route.php
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
If you want to make cross domain registration and make login for both A and B domains, you need to use session variable.
But its little difficult make cross domain session storage for variables. Because session will not store between A and B domains.
Here, I will tell how cache works instead of sessions in laravel.
When CROS ajax performing I will store data’s in Cache like below and will reload my domain.
Laravel will maintain inbuild cache’s.
Once ajax request completed your data will be stored in table as well as cache.
After that relaod your page and add below to code in your routes.php.
if(Cache::get('cors_cache_username') != '' && Cache::get('cors_cache_password') != '')
$credentials = array(
'username' => Cache::get('cors_cache_username'),
'password' => Cache::get('cors_cache_password')
It will check whether the cache are stored and will create login in A domain. You can write your code to make login for B domain. Now you can see your both domain registerd with same data and logged in.
Once your process completed delete the cache for should not affect other users.
Thanks!. If you like this article don’t forget to share and comment.