how would I add a subdomain to my cloudflare account for a specific domain on the fly? Is this possible to do, how do other websites tend to create subdomains in code?
Cloudflare has an API, https://www.cloudflare.com/docs/client-api.html#s5.1.
There is also a PHP library for Cloudflare as well. https://github.com/vexxhost/CloudFlare-API