dalecosp wrote:so your code would have to manipulate a (set of) DNS server(s)
Not necessarily (I definitely wouldn't want to do it that way! :p); you could instead just setup a DNS wildcard, e.g.:
*.example.com. 3600 IN CNAME www.example.com.
so that all requests that don't match an existing A record (e.g. existing subdomain such as 'www', etc.) will be handled as if you had requested 'www.example.com' instead.
Your browser, however, will still send the "my_nonexistant_subdomain.example.com" Host header to your PHP scripts (or even mod_rewrite), meaning you can use that value to perform whatever redirection/etc. you'd like.