: Subdomains and Site didn't know how to put this into to a title. Ok my idea is to have any subdomain working on my site, and for example if I type: what.example.com (my site has a unique
didn't know how to put this into to a title. Ok my idea is to have any subdomain working on my site, and for example if I type:
what.example.com
(my site has a unique folder for every subdomain, and within that folder, there is just a simple config file that sees the 'what' ( first part of subdomain) and loads database information based on the string and the whole site is populated. So if I put lol.example.com I have the same site, but with different information just based on database. Do you understand?
And then if people type the main site example.com or example.com they have the main site which is completely different from the subdomains.
So how can I do this?
I have this idea for a site of mine, in which the main site example.com will be a information site with a payment system. And when users pay me, I add their info to to an unique file where all other user info is located ( database info ), and then their site is whatever subdomain they have chosen .example.com , and there they have their info and can login.
edit: I just can't figure out how to allow any subdomain to be inserted in the url, loading the sub site, as grabbing the first part of the subdomain is easy and then everything would work.
More posts by @Fox8124981
2 Comments
Sorted by latest first Latest Oldest Best
I assume two posible scenarios:
In the first, each site has its own configuration file, named after the subdomain:
$host == $_SERVER['HTTP_HOST'];
$parts = explode('.',$host);
$subdomain = $parts[0];
if (file_exists('./site_config_'.$subdomain.'.php')){
include('./site_config_'.$subdomain.'.php');
}else{
include('./site_config_default.php');
}
This way, if you enter site1.mysite.com, site_config_site1.php will be searched for, if it doesn't exist, site_config_default.php
The second alternative implies a little more of work. You have to create a set of tables with a different prefix for each site:
$host == $_SERVER['HTTP_HOST'];
$parts = explode('.',$host);
$db_prefix = $parts[0];
// you should check here that the prefix actually exists
This way you will have:
site1_users
site1_posts
site1_tags
...
site2_users
site2_posts
site2_tags
...
Generally, you're describing wildcard DNS. But you'll have to talk to your host about implementing it, as they may or may not even support it, or only in particular cases(cf. Dreamhost).
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.