Skip to content

Instantly share code, notes, and snippets.

@emrahoruc
Created January 27, 2022 00:21
Show Gist options
  • Save emrahoruc/cbbe8d33d8aa83b47715c7c63dcb20a4 to your computer and use it in GitHub Desktop.
Save emrahoruc/cbbe8d33d8aa83b47715c7c63dcb20a4 to your computer and use it in GitHub Desktop.
Codeigniter 3.011 base_url detection
<?php
# Source: https://codeigniter.com/userguide3/installation/upgrade_303.html
$config['base_url'] = ['domain1.tld', 'domain2.tld'];
if (in_array($_SERVER['HTTP_HOST'], $config['base_url'], true)) {
$domain = $_SERVER['HTTP_HOST'];
} else {
$domain = $config['base_url'][0];
}
if (! empty($_SERVER['HTTPS'])) {
$config['base_url'] = 'https://'.$domain;
} else {
$config['base_url'] = 'http://'.$domain;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment