How to realize the cross-site setting of cookie

premise: under the domain name ".myweb.com", there are two sites A (a.myweb.com) and B (b.myweb.com), and single sign-on can be performed between the two sites. The logic of single sign-on is that when a user visits any page under a certain site, the cookie, that determines whether there is session information under the current site or not visits the Login site (login.myweb.com), the cookie, that determines whether there is session information in the Login site is redirected to the login page, and if so, it jumps to the page before the judgment is executed. When a user logs in at a site, the cookie of the current session information is stored in the current site and in the Login site. The logic of single sign-on can no longer be modified for objective reasons.

problem: the content of an iframe,iframe in site An is a page of site B, but the redirection in single sign-on uses window.top, so it will cause the entire page to jump to site B, so you want to set the cookie of the session information of site A to site B before iframe renders the page of site B, so that you can not visit the Login site and trigger the redirection.

I"m using the jq.cookie plug-in, but in actual development, executing the following code in site A doesn"t work. By consulting the data, it should be caused by the cross-domain setting of cookie. Is there any solution?

$.cookie("_serviceId","f850...", { domain: ".b.myweb.com",path: "/"});
Apr.09,2021

if you want to share cookie under the myweb.com domain, just change domain to .myweb.com .


it is one way to directly set the cookie of the main domain .xxx.com . In addition, it depends on the timing of your jump. If it is a server redirection, you cannot use js to do cross-page. If js judges cookie, you can use iframe cross-domain method to get cookie before jumping.

if you want to set it forcibly, site An and site B can agree on an encryption method. When embedding iframe, src takes the encrypted cookie content, and site B detects the field and decrypts it and then set-cookie it directly. Similar to token

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3d2e6-2c37f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3d2e6-2c37f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?