How can one ensure that a PHP script for creating "Fake" subdomains works with both www and non-www versions?

To ensure that a PHP script for creating "Fake" subdomains works with both www and non-www versions, you can check the HTTP_HOST server variable in the script and handle the subdomain creation accordingly. If the HTTP_HOST includes "www", you can strip it out before creating the subdomain to ensure consistency.

$subdomain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
// Create the fake subdomain using $subdomain variable