How To Automatically Log In On Main/subdomain?

I’m building a site that has several subdomains (sub.example.com, sub2.xample.com, etc.)

Users are in the same table so I’m wondering how (if) it’s possible to automatically log-in a user who logs in on any site (www, sub1, sub2, etc.)

Notes:

  • all the sites share the same yii directory

  • every site (subdomain) has it’s own separate folder and so it’s own /img, /css, /protected, etc.

  • all the sites access the same database

  • the www is intended for visitors/buyers

  • the subdomains are intended for contributors and staff members.

Why would I log-in a user to www when he is logged in via sub1? Because - for example staff members - see extra links on www items, such as edit, delete, manage, etc. It’s annoying to log in to sub1 and then click a link that takes to www and at www see myself not logged in…

The question: how can I log in a user to ALL (sub)domains when he logs in from a given (sub)domain? (Logout should log out him from everywhere…)