train
train

Reputation: 610

Best way to keep track of subdomain for guests

I am trying to create subdomains for users as each has their own "website". (user.domain.com) This is all "virtual" as all the files, controllers, folders, etc are the same. Everything is dynamically created. I think I've got all the DNS, mod_rewrite, htaccess, etc stuff down, but I've got another problem.

The problem is when a guest (non-user) visits a user's website (user.domain.com). An example to illustrate this:

  1. Guest types url with subdomain (btw, I'm using php) and controller dynamically loads up the user website based on the subdomain.
  2. Guest clicks on a link on the page and gets a new page from server. Problem is that the new page doesn't have the subdomain anymore as all the links are the same. Only the content is different and dynamically loaded.

So the question is, How do I keep track of which subdomain the guest is on? Since the client is a guest and not a logged in user, I can't look at the logged in user's information.

I am just interested in ideas of what the best implementation would be. Should I keep some variable in the session and keep checking that on each page? Should I pass a POST/GET variable with each link and then have the controller read that?

Upvotes: 1

Views: 103

Answers (1)

superphonic
superphonic

Reputation: 8074

 $_SERVER['SERVER_NAME']

This will give you the domain, just keep it in the session.

Upvotes: 1

Related Questions