Subdomains and Site
===

I 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 www.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.