Create sub domains

Hi All,

Wondered if anyone could help or point me in the right direction.

I am building a site that users can sign up to and it creates a subdomain and pages and photos under there own sub domain.

Currently I don’t think what I have done is the best way of doing it. Currently when you create a user I have written that it basically creates the subdomain and copies the whole website to the new subdomain, not the best for space, what I want to know is how I can get it to create a virtual subdomain and that when people type in the address eg subdomain.site.com it pulls up the data from a database and puts the info into a template to be displayed

I have a basic understanding of databases it’s the subdomain bit I need help with

Hope this makes sense

Thanks

Sent from my iPhone using Tapatalk

That depends on which webserver you’re using, and then there are multiple ways of handling it.

One way would be to configure the webserver to pass all traffic on the subdomains (*.yourdomain.com) to your PHP script, and then you use the subdomain name to figure out which site to display.

Pseudo code:


$host = $_SERVER['SERVER_NAME'];
$host = explode('.', $host);
$sub = $host[0]; // e.g. mysub.yoursite.com would give $sub = mysub

Cool I use hostgator so will give it a go, thanks for your help

Sent from my iPhone using Tapatalk

You’ll have to check out hostgator’s control panel to see what options they have for wildcarding subdomains. Perhaps their support can tell you more. Good luck :wink: