Subdomains

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WebD
Forum Newbie
Posts: 19
Joined: Tue Aug 26, 2003 11:30 am

Subdomains

Post 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!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Subdomains

Post by Christopher »

Sub-domain are done using DNS. If you don't want to do DNS entries then do: domain.com/anything
(#10850)
WebD
Forum Newbie
Posts: 19
Joined: Tue Aug 26, 2003 11:30 am

Re: Subdomains

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Subdomains

Post 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?
(#10850)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Subdomains

Post 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...
WebD
Forum Newbie
Posts: 19
Joined: Tue Aug 26, 2003 11:30 am

Re: Subdomains

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Subdomains

Post 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.
(#10850)
WebD
Forum Newbie
Posts: 19
Joined: Tue Aug 26, 2003 11:30 am

Re: Subdomains

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Subdomains

Post 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.
WebD
Forum Newbie
Posts: 19
Joined: Tue Aug 26, 2003 11:30 am

Re: Subdomains

Post 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' ?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Subdomains

Post 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.
(#10850)
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Subdomains

Post 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.
WebD
Forum Newbie
Posts: 19
Joined: Tue Aug 26, 2003 11:30 am

Re: Subdomains

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Subdomains

Post 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.
Post Reply