Welcome Guest, Not a member yet? Register   Sign In
Subdomain(s) and S_SERVER['HTTP_HOST']
#1

Hi guys,

Can you tell me if the following is a good practice or not:

I want to create a few subdomains so that they use the same application directory as the main site.

Is this correct to setup Sconfig['base_url'] = S_SERVER['HTTP_HOST'] ?

Thank you
Reply
#2

No, you should do it like this:
https://www.codeigniter.com/userguide3/i...e_303.html
Reply
#3

(12-22-2017, 08:49 AM)jreklund Wrote: No, you should do it like this:
https://www.codeigniter.com/userguide3/i...e_303.html

Thank you! Wink
Reply
#4

(This post was last modified: 12-26-2017, 08:49 AM by ciadmin. Edit Reason: SEO spam )

You can use this code
$allowed_domains = array('domain1.tld', 'domain2.tld');
$default_domain  = 'domain1.tld';

if (in_array($_SERVER['HTTP_HOST'], $allowed_domains, TRUE))
{
        $domain = $_SERVER['HTTP_HOST'];
}
else
{
        $domain = $default_domain;
}

if ( ! empty($_SERVER['HTTPS']))
{
        $config['base_url'] = 'https://'.$domain;
}
else
{
        $config['base_url'] = 'http://'.$domain;
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB