Welcome to WebmasterWorld Guest from 3.227.249.234

Forum Moderators: phranque

Setting a cookie across domains

     
12:03 am on Sep 18, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Mar 15, 2013
posts: 1193
votes: 119


Since 3rd party cookies are going the way of Friendster, my plans are gonna have to change :-(

I have about 60 domains parked on top of the main domain, and I show different content based on the domain. But I was planning to start diverting at least all mobile users from the parked domain to the main domain, with the theory that a single domain with 15 million monthly pageviews might be worth more to Adsense than 60 domains with the same traffic spread out.

Since the users can log in to each domain separately, I was adding a bit of Javascript to the footer of each page to set a logged-in cookie on the main domain:

// getCookie() and setCookie() are separate functions I've been using for years)

// on the parked domain
<script>
var username = getCookie('username');
</script>
<script src='https://www.example.com/login.js'></script>

// login.js on the main domain
if (!getCookie('username')
// cookie_name, cookie_value, days before expiration
setCookie('username', username, 365);


But I guess that this isn't going to work, now that 3rd party cookies are being blocked?

So can you guys and gals suggest another way that I might log the user in across domains? I can work with PHP or Javascript, and I'm using Apache if it matters.
2:31 am on Sept 18, 2019 (gmt 0)

Senior Member

WebmasterWorld Senior Member Top Contributors Of The Month

joined:Apr 1, 2016
posts:2711
votes: 822


You can use JWT tokens in place of cookies. This is typically used for REST api's or similar applications, but it may work for you. It's worth a look, but it is rather technical.

[jwt.io...]