Suppose I want my site to be accessible at https://www.example.com
and https://example.com
.
Is it possible to set a cookie when visiting one domain so that it is accessible in the other?
Yes you can, try setting the cookie for .example.com
as domain. That way, the cookie will be valid for every subdomain of yours.
For example, PHP sessions would be like this: session_set_cookie_params(0, '/', '.example.com');