How to redirect a user to the Last Domain Browsed on a machine

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Bosire's picture

Hello. I have a question, what will i do to save on a browser the last domain a user was on either on a cookie or a session or anythin else that will work so that whenever they type the main domain they are redirected to the sub domain they were on last even if the browser was closed and it is a new user who is trying the main domain. I have about 3 sub domains and the main domain. i am using domain access. See example below:

main.com <== TLD sub.main.com <== Sub Domain 1 sub2.main.com <== Sub Domain 2

user types in main.com and select sub.main.com and starts browsing. That say was yesterday. Today, he or she returns to the same machine and types the domain.com but is re-directed to a sub domain.com.

How can I implement this in a module? Please Help!