base.php 723 Bytes
Newer Older
Andreas Müller's avatar
Andreas Müller committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php

// Define the current directory as base directory
define('BASEDIR', str_replace('\\', '/', __DIR__));

$url = '';
if (file_exists(BASEDIR.'/url.txt'))
{
	$url = trim(file_get_contents(BASEDIR.'/url.txt'));
}

if (empty($url))
{
	// Corresponding to the current directory, define the url as base url
	$url = str_replace($_SERVER['DOCUMENT_ROOT'], 'http://'.$_SERVER['HTTP_HOST'], BASEDIR);
}

define('ISHTTPS', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ||
	(isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] == 'https'));

if (ISHTTPS)
{
	$url = str_replace("http", "https", $url);
}

Andreas Müller's avatar
Andreas Müller committed
26 27 28 29 30
if (substr($url, -1) == '/')
{
	$url = substr($url, 0, strlen($url) -1);
}

Andreas Müller's avatar
Andreas Müller committed
31 32 33
define('BASEURL', $url);

?>