I have a project I’m beginning work on and have a few specific requirements that I am not sure how to go about. First of all, there will be many clients, each with their own domain name in the following format:
www.username.domain.com
Overall, the site will look exactly the same except for the initial page which would have the clients contact information, picture, etc. Also, there will be a few forms spread about the site and I would like to associate those submissions to that particular client, based on client_id or something.
In my head, I would think you could just point the subdomain to the base code. Then from there, explode the url to get the username and pull appropriate data from the db. But, how would you deal with $config[‘base_url’] in the config file?
You guys have any ideas or perhaps a better means of doing this?
I once constructed a site that made use of dynamic subdomains. I went about almost exactly the way you are doing it right name. Here’s a snippet of the config file of that site.
The following snippet fixes the constants when you dont have a subdomain at all (e.g. domain.com, because without this you get domaincom as the TLD… not exactly correct)
Enjoy, and thanks for getting the ball rolling in my head for this!
The only downside is that creating a new account would require a waiting period as the new subdomain would need to propagate to all of the DNS servers of the interweb. That’s why most sites use the ‘www.domain.com/username’ format. In that same vein, browsing users may be a few milliseconds slower as each profile view now requires the browser to hit up DNS.
The only downside is that creating a new account would require a waiting period as the new subdomain would need to propagate to all of the DNS servers of the interweb. That’s why most sites use the ‘www.domain.com/username’ format. In that same vein, browsing users may be a few milliseconds slower as each profile view now requires the browser to hit up DNS.
Actually, no. Wildcard DNS prevents this. I can type in any subdomain and it is already resolved.
Windows does cache DNS calls (which can be cleared using ipconfig /flushdns). BUT… doesn’t a new subdomain require a new DNS request as it’s basically like a new domain name? If not, the idea of “subdomains take time to propagate DNS” wouldn’t make sense. I *think* using subdomains like this would basically cause the local DNS cache to be useless for those URLs.
Yes, of course the DNS is needed for the initial request, but with wildcard DNS, once that’s propagated, that’s it. All requests to any domain name will be forwarded to the same server, and the local DNS should sort out the rest. When a new subdomain is added, no propagation is necessary, only the local DNS needs to know where to map the subdomains. I thought that was the whole point of what brendanc was saying?
So the local machine will actually cache the wildcard? In windows you can manually add DNS info in the hosts file, but it doesn’t support wildcards. I though the local cache would be similar. For instance, no matter which user you lookup, your ISP’s DNS server returns the IP for whatever the server is, but when the local machine caches it, it doesn’t cache an entry like this:
*.domain.com 235.123.523.21
It cache’s the static version, which is the actual request that was made:
jimsmith.domain.com 235.123.523.21
Which means each request to a new subdomain would still require the browser to hit up the DNS server.
I’m not really sure about this, I just thought that’s how it worked. Can anyone confirm?
You may be right about needing to make a DNS request, but I would think… in the case of having a wildcard DNS entry, that even if you have to make a request, the lookup will be so fast that it won’t matter (matter of milliseconds).
Either way, I didn’t mean to derail a 2 year old thread into talking about DNS caching I was just adding my little snippet of code to handle not having a subdomain included.
No, you can’t cache a wildcard domain… brandanc’s point is that you don’t need to wait for any specific domain name to propagate, I don’t know why you seem to have trouble letting go of the whole DNS query thing…
And yes, a new request needs to be made for each subdomain. The browser is oblivious to the fact that the the subdomain is a wildcard - only the DNS servers know.
codeigniter.com clearly has wildcard DNS enabled, or do you really think they added those 4 subdomains? Try it yourself with any subdomain of your choice. If it’s not in use, it will direct you to the codeigniter.com Web site.
Now, let’s say we wanted to add http://slowgary.codeigniter.com/. We can! It already resolves, we just need to configure the local name server to send that request to whatever Web root you’ve been designated.
Windows cannot cache wildcard subdomains. Instead, it caches them by the name that you requested. It’s the DNS servers that actually store the wildcard DNS setting.
HA! I hadn’t realized it was such an old thread or I wouldn’t have responded in the first place.
I understand that DNS propagation will not be an issue, and I don’t have an issue with the non-cache-able DNS info, I just wanted to make sure I (and any readers) understand the pros and cons of this approach. I personally don’t think trading local DNS caching for subdomain user accounts is worthwhile and I’m sure ISP would agree.
Sorry, I don’t understand the trade off. Whether a named subdomain is set up, or wildcard DNS, it’s still only one DNS call. I think wildcard DNS is a Godsend. The number of times I configured my subdomain wrongly and had to wait 8-24 hours to find out is ridiculous. With wildcard DNS, my subdomains start resolving within 10 minutes.