Q3: How do I set the cookie path and domain?

Answer

Use the extended SetCookieExt() function to set path and domain:

&SetCookieExt($name, $value, $expire, $path, $domain, $secure);

Parameters:

  • $path: URL path where cookie is valid (default: "/")
  • $domain: Domain for the cookie (default: current domain)
  • $secure: Set to 1 for HTTPS only

Examples:

# Cookie for entire site
&SetCookieExt("user", $id, "30d", "/", "", 0);

# Cookie for /admin/ section only
&SetCookieExt("admin", $token, "1h", "/admin/", "", 1);

# Cookie for all subdomains
&SetCookieExt("session", $data, "1d", "/", ".example.com", 0);
Previous CookieLib FAQ