0

I set session cookies but it creates new cookies. I'm tired of this Do you know how to fix it? Code:

document.cookie = ".ROBLOSECURITY=cookie; expires=session; path=/";
nutza tv ch
  • 1
  • 1
  • 3
  • What's the difference between setting a cookie and creating a cookie? Please elaborate – smac89 Jan 20 '22 at 03:13
  • https://imgur.com/a/qGVHV4Y likes this @smac89 – nutza tv ch Jan 20 '22 at 04:02
  • 1
    I'm no cookie expert, but it looks like the domain where you are setting the cookie is not the same. One is at `www.roblox.com` while the other is at `robolox.com`. From what I've read, you can only set cookies on the most specific domain you are on – smac89 Jan 20 '22 at 04:12
  • 1
    Perhaps you can try specifying the domain. So something like `document.cookie = ".ROBLOSECURITY=cookie; expires=session; path=/; domain=.roblox.com"` – smac89 Jan 20 '22 at 04:14
  • See if anything said here helps you: https://stackoverflow.com/questions/45700816/how-can-i-get-the-cookies-from-a-subdomain – smac89 Jan 20 '22 at 04:18

2 Answers2

1

Let's check documentation

;domain=domain (e.g., 'example.com' or 'subdomain.example.com'). If not specified, this defaults to the host portion of the current document location. Contrary to earlier specifications, leading dots in domain names are ignored, but browsers may decline to set the cookie containing such dots. If a domain is specified, subdomains are always included.

Note: The domain must match the domain of the JavaScript origin. Setting cookies to foreign domains will be silently ignored.

Your first cookie with domain www.roblox.com will be accessible only at www.roblox.com/... page but .roblox.com's cookie may be accessed by JS from all roblox.com subdomains.

Here is a good answer

So as @smac89 wrote in comment, You should add domain when create new cookie

document.cookie = ".ROBLOSECURITY=cookie; expires=session; path=/; domain=.roblox.com"
rzlvmp
  • 7,512
  • 5
  • 16
  • 45
0

There is no syntax for what you want.

You can either not set the expiration value, the cookie will expire at the end of the session, or choose an arbitrarily large value.

Be aware that some browsers have problems with dates past 2038 (when the Unix epoch time exceeds a 32-bit integer).

See : https://stackoverflow.com/a/532660/1901857

mvetois
  • 111
  • 11