سؤال

Is it possible to to access web with url example.com but variables inside php (like SERVER_NAME) would act like sub.example.com?

We made wrong decision during development and now we are actually stuck with two separate versions of software. One for example.com and other for automatically generated subdomains. We could reserver one subdomain to act as our main domain, but we don't want that sub. example.com part.

هل كانت مفيدة؟

المحلول

You should add some checks, for example:

function hasSubdomain($url) {
    $parsed = parse_url($url);
    $exploded = explode('.', $parsed["host"]);
    if(count($exploded) > 2){
       return true;
    }else{
       return false;
    }
}

if(!hasSubdomain($_SERVER['SERVER_NAME'])){
   $_SERVER['SERVER_NAME']="sub.example.com";
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top