What you actually need is wildcard subdomains. Like, *.example.com would point to the same place as example.com and Apache or IIS would treat it the same. In PHP you would then use $SERVER['HTTPHOST'] to find if the subdomain is a valid username.
However, I must recommend against such practice. While it is nifty, it is a lot of work to get right, and can have security implications.