9

Is it possible to set an auth cookie that would be valid on:

  • sub1.domain.com
  • sub2.domain.com

Or will each subdomain always require it's own cookie?

cjm2671
  • 18,348
  • 31
  • 102
  • 161

1 Answers1

11

You can use cookies across sub domains if you specify the cookie to be attached to the domain:

.domain.com

note the dot in front.

See here for reference:

http://www.jotlab.com/2008/04/08/howto-get-cookies-across-subdomains-php/

Richard
  • 21,728
  • 13
  • 62
  • 101
  • 1
    It should be noted that this does make the cookie also valid for any other subdomain of *example.com* like `sub3.example.com` and `foobar.sub1.example.com` etc. – Gumbo Dec 16 '11 at 09:14
  • 1
    Also you cant use secure flag by this way. – M Rostami Aug 16 '14 at 11:49
  • Mb Rostami - Thanks, your comment provides the information I am looking for. Any chance you have a reference for that information? – Jeremy A. West Sep 18 '15 at 15:54