1

I have two laravel project with virtual host name 1) my.dev.com and 2) your.dev.com

I have create api for set cookie for cross domain and api is located at your.dev.com

Route::middleware('cors')->get('/hello', function () {
$cookie = Cookie::make('custom_cookie', 'hello_world', 10, "/", '.dev.com');
return response()->json('Hello worlds')->withCookie($cookie);

});

I make api call from my.dev.com and code is like this

<html>
<head>
    <title>CORS</title>
</head>
<body>
    <button type="button">Call API</button>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $("body").on("click","button",function () {
                $.get("http://my.dev.com/api/hello",function(data){
                    alert(data);
                });
            })
        });
    </script>
</body>

When I click Call API button from my.dev.com I get response Hello worlds but Cookie is not set your.dev.com

enter image description here

Even Cookie not set any .dev.com virtual host

I want to set Cookie at your.dev.com from my.dev.com with help of Ajax and code already posted here.

Your help would be appreciated.

Dharmesh Rakholia
  • 1,101
  • 7
  • 18
  • Possible duplicate of [Share cookie between subdomain and domain](https://stackoverflow.com/questions/18492576/share-cookie-between-subdomain-and-domain) – Devon Jul 09 '18 at 16:59
  • According to the duplicate, "all modern browsers respect the newer specification RFC 6265, and will ignore any leading dot, meaning you can use the cookie on subdomains as well as the top-level domain." – Devon Jul 09 '18 at 17:00
  • You might need to set the withCredentials flag for the AJAX request in this situation, I think. – CBroe Jul 10 '18 at 06:59
  • I want set cookie using Ajax to another sub domain – Dharmesh Rakholia Jul 10 '18 at 13:05

0 Answers0