Subdomains
Moderator: General Moderators
Subdomains
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!
Thanks for help!
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Subdomains
Sub-domain are done using DNS. If you don't want to do DNS entries then do: domain.com/anything
(#10850)
Re: Subdomains
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?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Subdomains
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?
(#10850)
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Subdomains
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
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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Subdomains
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.
(#10850)
Re: Subdomains
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.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Subdomains
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.
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
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' ?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Subdomains
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.
(#10850)
- Skoalbasher
- Forum Contributor
- Posts: 147
- Joined: Thu Feb 07, 2008 8:09 pm
Re: Subdomains
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
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?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: 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.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?