How to set cookies in Magento for WWW domain
No, they don't need to match.
The cookie domain defined, where the browser sends the cookies to:
- www.domain.com means the cookie is only sent to www.domain.com
- .domain.com sends the cookie to domain.com (I think) and every suddomain, so you can exchange informations between different subdomains/servers