Skip to content

Commit

Permalink
better fix for site_root autodetection - seemingly SCRIPT_URI is not …
Browse files Browse the repository at this point in the history
…always present
  • Loading branch information
DavidGoodwin committed May 23, 2014
1 parent 2d350dd commit 0d45d6c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion website_code/php/database_library_sqlite.php
Expand Up @@ -74,10 +74,20 @@ function database_setup($database_location) {
die("SQLite installation failed.");
}

$site_root = $_SERVER['SCRIPT_URI'];
$http = 'http';
if(isset($_SERVER['HTTPS'])) {
$http = 'https';
}
$site_root = $http . '://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'] . '/';
/* $site_root = $_SERVER['SCRIPT_URI']; */
if(preg_match('!(.*)/([a-z]+.php)$!', $site_root, $matches)) {
$site_root = $matches[1] . '/';
}
while(substr($site_root, -1) == '/') {
$site_root = substr($site_root, 0, -1);
}
$site_root .= '/';

// this ought to work and cope with https vs http urls - as long as the first url requested isn't within a subdir.
$db->query("UPDATE sitedetails SET site_url = '" . $db->escapeString($site_root). "'");

Expand Down

0 comments on commit 0d45d6c

Please sign in to comment.