Page 1 of 1
Subdomains
Posted: Sun Feb 10, 2008 12:14 pm
by WebD
Hi, I am trying to make a groups script where every group has a subdomain. I am curious on if there is a way to do this without having to add each subdomain to the DNS. Is there some way to go anything.domain.com forwards to a script where the script takes 'anything' as a variable and outputs the content from a database or something based on the 'anything' variable?
Thanks for help!
Re: Subdomains
Posted: Sun Feb 10, 2008 12:50 pm
by Christopher
Sub-domain are done using DNS. If you don't want to do DNS entries then do: domain.com/anything
Re: Subdomains
Posted: Sun Feb 10, 2008 2:11 pm
by WebD
I know they are done using DNS, I just don't want to have to enter each one individually. Is there a way then, to add them automatically when the group is created?
Re: Subdomains
Posted: Sun Feb 10, 2008 2:24 pm
by Christopher
I don't know what interface you have to add DNS entries, but it is possible that the PHP script that adds the group could also add the DNS entry. Can you add a DNS entry from the command line?
Re: Subdomains
Posted: Sun Feb 10, 2008 7:22 pm
by Chris Corbyn
Look into using PowerDNS since you can back it on multiple backends... the default being BIND9, but it has MySQL and PgSQL backends too. I used to admin a PDNS server in my last job using a MySQL backend...
Re: Subdomains
Posted: Sun Feb 10, 2008 8:44 pm
by WebD
arborint: I have a control panel right now that I add DNS entries through, although I do have shell access... would that work? The idea i am going for is kind of like Facebook, where all their networks have sub-domains.
Re: Subdomains
Posted: Sun Feb 10, 2008 9:03 pm
by Christopher
Check with your hosting company to see if you have a way to add DNS entries via the command line. The you can use PHP's exec() function to add entries.
Re: Subdomains
Posted: Sun Feb 10, 2008 9:36 pm
by WebD
I just fired an email off to my hosting company to see if that is possible. Either way though, what would be the best way to make each subdomain point to each group using php? Right now I have all of the group info in a mysql database.
Re: Subdomains
Posted: Mon Feb 11, 2008 5:37 am
by Chris Corbyn
If you can get all the subdomains to alias to the same codebase then you likely just want to check the value of $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME'].
I believe there are potential vulnerabilities with this so I wouldn't ever suggest directly using those values on a web page without sanitization, but in logic they should give you what you need.
EDIT | You can emulate this scenario locally by editting /etc/hosts if you're on a mac or linux, or the windows HOSTS file (I forget where it is, somewhere in \SYSTEM)... just point some other domains to 127.0.0.1 so your computer treats them as local domains.
Re: Subdomains
Posted: Mon Feb 11, 2008 10:35 am
by WebD
So, I did recieve a reply from my hosting provider, and turns out I don't have access to the command line. I do have shell access though.. is there any way I could add the subdomains that way? what do you mean 'without sanitization' ?
Re: Subdomains
Posted: Mon Feb 11, 2008 11:27 am
by Christopher
Typically "command line" and "shell access" mean the same thing. What you really want to know is if there is a program on the server that you can exec() or a web service to one of their servers that you can use to add DNS entries.
Re: Subdomains
Posted: Mon Feb 11, 2008 12:09 pm
by Skoalbasher
My host bluehost.com has a cool feature in CPanel where you just tell it what subdomain you want and the folder you want it to point to. It's pretty cool... I dunno if you can do make a signup form to add them, that'd be nice too, but just ask your host, they should be able to set something up for you.
Re: Subdomains
Posted: Mon Feb 11, 2008 3:54 pm
by WebD
Yeah I can access the shell thru an ssh client built into the control panel. I think its the plesk control panel. I should be able to use the exec() command in php then to create the subdomains?
Re: Subdomains
Posted: Mon Feb 11, 2008 8:14 pm
by Chris Corbyn
WebD wrote:Yeah I can access the shell thru an ssh client built into the control panel. I think its the plesk control panel. I should be able to use the exec() command in php then to create the subdomains?
Only if your host provide such a command line tool, and I'm guessing they don't. If your control panel is able to add domains you could always go about it in a more ad-hoc way and use cURL.