I have this line:

document.cookie =textbox+this.getParameterByName("idProd")+'='+document.getElementById('name').value+'; domain=mydomain.com; expires='+dia.toGMTString()+'; path=/';

This cookie should work on the mydomain.com and all of its subdomains to read and write, correct??? Doesnt work online but works on local thats why I ask.

Thanks!

Dani AI

Generated

A few clarifications and a short debug checklist that complement what and discussed.

If a cookie works on localhost but not on your live host the cause is usually not the order of attributes (the spec accepts attributes in any order) but one of these: how the browser interprets the host/domain relationship, browser-enforced public-suffix rules, connection/security attributes (Secure, HttpOnly, SameSite), or browser privacy/third-party-cookie blocking. Modern user agents follow RFC 6265, and treat a leading dot on the Domain attribute as non-essential; consult the spec and current MDN docs for exact parsing rules and recent SameSite behavior.

Practical checklist to reproduce and diagnose the problem:

  • Inspect Storage/Cookies in the browser devtools on each subdomain to see which host actually stored the cookie and any console warnings.
  • Use the Network panel to watch Set-Cookie headers (server-set cookies are easier to reason about than JS-only ones).
  • Verify the cookie is not HttpOnly if you expect to read it from JavaScript, and that Secure/SameSite flags match your HTTPS and cross-site usage.
  • Remember public-suffix rules: browsers refuse cookies for certain top-level/registrable suffixes (see the Public Suffix List) — that will block cross-domain sharing.
  • When testing locally, map test hostnames (eg. subdomain entries in hosts) so behavior matches live host rules.

If those checks fail, create a minimal server response that sets a cookie (no HttpOnly, path=/) and confirm whether it appears on each subdomain. References: MDN Document.cookie, MDN Set-Cookie header, and RFC 6265.

Recommended Answers

All 8 Replies

Noone has any idea about this?

IIRC, it was something like this: document.cookie = "key=value,path=/;domain=example.com";

Order matters?

Not sure.

Well thanks but helpful isnt exactly what I call you answer

Thank you pritaeas....

The way I have it implanted should work but nothing.......

states that domain should start with a dot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.