Auto-detect base URL

This commit is contained in:
Sebastian Meyer 2017-05-21 20:01:51 +02:00
parent a79d621fd2
commit fd2fa1ada3
2 changed files with 9 additions and 5 deletions

View File

@ -39,10 +39,17 @@ reset($records);
ksort($timestamps);
reset($timestamps);
// Get current base URL
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
$baseURL = 'https://'.$_SERVER['HTTP_HOST'].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
} else {
$baseURL = 'http://'.$_SERVER['HTTP_HOST'].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
}
// Build the Identify response
$identifyResponse = array(
'repositoryName' => $config['repositoryName'],
'baseURL' => $config['baseURL'],
'baseURL' => $baseURL,
'protocolVersion' => '2.0',
'adminEmail' => $config['adminEmail'],
'earliestDatestamp' => gmdate('Y-m-d\TH:i:s\Z', key($timestamps)),
@ -51,7 +58,7 @@ $identifyResponse = array(
);
$oai2 = new OAI2Server(
'http://'.$_SERVER['HTTP_HOST'].parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH),
$baseURL,
$_GET,
$identifyResponse,
array(

View File

@ -29,9 +29,6 @@ $config = array();
// A human readable name for the repository
$config['repositoryName'] = 'Simple OAI 2.0 Data Provider';
// The base URL of the repository, i.e. the directory you deployed the files to
$config['baseURL'] = 'http://www.example.org/oai2/';
// Email address for contacting the repository owner
$config['adminEmail'] = 'admin@example.org';