Created
June 16, 2011 19:14
-
-
Save zerocrates/1029997 to your computer and use it in GitHub Desktop.
modified WEB_ROOT definition for Omeka to handle non-standard ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _define_web_root() | |
{ | |
// Create base URL | |
$base_root = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http'; | |
// As $_SERVER['HTTP_HOST'] is user input, ensure it only contains | |
// characters allowed in hostnames. | |
$base_url = $base_root .= '://' . preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']); | |
// Handle non-standard ports | |
$port = $_SERVER['SERVER_PORT']; | |
if (($base_root == 'http' && $port != '80') || ($base_root == 'https' && $port != '443')) { | |
$base_url .= ":$port"; | |
} | |
// $_SERVER['SCRIPT_NAME'] can, in contrast to $_SERVER['PHP_SELF'], not | |
// be modified by a visitor. | |
if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\,/')) { | |
$base_path = "/$dir"; | |
$base_url .= $base_path; | |
$base_path .= '/'; | |
} else { | |
$base_path = '/'; | |
} | |
// WEB_ROOT is always the root of the site, whereas WEB_DIR depends on the | |
// bootstrap used (public/admin) | |
// @hack Remove the '/admin' part of the URL by regex (only if necessary) | |
if (defined('ADMIN')) { | |
$dir = preg_replace('/(.*)admin$/', '$1', $dir, 1); | |
$dir = rtrim($dir, '/'); | |
} | |
define('WEB_ROOT', $base_root . (!empty($dir) ? '/' . $dir : '') ); | |
define('WEB_DIR', $base_url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment