benjamin benjamin - 3 years ago 208
PHP Question

Dynamically assign a subdomain that is not related to a folder

I need to create a sub-domain dynamically. What my code does is load html code from DB then displays it.

There are no sub folders or anything like that. I want a url that looks like this
to look like

Answer Source

Something as basic as this should do the trick:

// assuming you have $_SERVER['SERVER_NAME'] reliably set and available
// i.e. something like $_SERVER['SERVER_NAME'] = '';

$subdomain = $_GET['website'] . '.' . $_SERVER['SERVER_NAME'];

You might want to validate the input etc.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download