mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: abstracted protocol detection out to Director::protocol() #5450 (from r107094)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112550 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
25a0c3e7fb
commit
6ee6ab4ee7
@ -373,10 +373,8 @@ class Director {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$s = (isset($_SERVER['SSL']) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')) ? 's' : '';
|
|
||||||
|
|
||||||
if(isset($_SERVER['HTTP_HOST'])) {
|
if(isset($_SERVER['HTTP_HOST'])) {
|
||||||
return "http$s://" . $_SERVER['HTTP_HOST'];
|
return Director::protocol() . $_SERVER['HTTP_HOST'];
|
||||||
} else {
|
} else {
|
||||||
global $_FILE_TO_URL_MAPPING;
|
global $_FILE_TO_URL_MAPPING;
|
||||||
if(Director::is_cli() && isset($_FILE_TO_URL_MAPPING)) $errorSuggestion = ' You probably want to define '.
|
if(Director::is_cli() && isset($_FILE_TO_URL_MAPPING)) $errorSuggestion = ' You probably want to define '.
|
||||||
@ -391,6 +389,14 @@ class Director {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current protocol that the site is running under
|
||||||
|
*
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
static function protocol() {
|
||||||
|
return (isset($_SERVER['SSL']) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')) ? 'https://' : 'http://';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirect to another page.
|
* Redirect to another page.
|
||||||
@ -593,9 +599,8 @@ class Director {
|
|||||||
$login = "";
|
$login = "";
|
||||||
|
|
||||||
if(isset($_SERVER['PHP_AUTH_USER'])) $login = "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@";
|
if(isset($_SERVER['PHP_AUTH_USER'])) $login = "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@";
|
||||||
if(isset($_SERVER['SSL']) && $_SERVER['SSL'] != 'Off') $s = "s";
|
|
||||||
|
|
||||||
return "http$s://" . $login . $_SERVER['HTTP_HOST'] . Director::baseURL();
|
return Director::protocol() . $login . $_SERVER['HTTP_HOST'] . Director::baseURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -607,7 +612,7 @@ class Director {
|
|||||||
* </code>
|
* </code>
|
||||||
*/
|
*/
|
||||||
static function forceSSL() {
|
static function forceSSL() {
|
||||||
if((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && !Director::isDev() && !Director::is_cli()) {
|
if((Director::protocol() != "https://") && !Director::isDev() && !Director::is_cli()) {
|
||||||
$destURL = str_replace('http:', 'https:', Director::absoluteURL($_SERVER['REQUEST_URI']));
|
$destURL = str_replace('http:', 'https:', Director::absoluteURL($_SERVER['REQUEST_URI']));
|
||||||
|
|
||||||
header("Location: $destURL", true, 301);
|
header("Location: $destURL", true, 301);
|
||||||
@ -620,11 +625,7 @@ class Director {
|
|||||||
*/
|
*/
|
||||||
static function forceWWW() {
|
static function forceWWW() {
|
||||||
if(!Director::isDev() && !Director::isTest() && strpos($_SERVER['HTTP_HOST'], 'www') !== 0) {
|
if(!Director::isDev() && !Director::isTest() && strpos($_SERVER['HTTP_HOST'], 'www') !== 0) {
|
||||||
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
|
str_replace(Director::protocol(), Director::protocol() . 'www.', Director::absoluteURL($_SERVER['REQUEST_URI']));
|
||||||
$destURL = str_replace('https://', 'https://www.', Director::absoluteURL($_SERVER['REQUEST_URI']));
|
|
||||||
} else {
|
|
||||||
$destURL = str_replace('http://', 'http://www.', Director::absoluteURL($_SERVER['REQUEST_URI']));
|
|
||||||
}
|
|
||||||
|
|
||||||
header("Location: $destURL", true, 301);
|
header("Location: $destURL", true, 301);
|
||||||
die("<h1>Your browser is not accepting header redirects</h1><p>Please <a href=\"$destURL\">click here</a>");
|
die("<h1>Your browser is not accepting header redirects</h1><p>Please <a href=\"$destURL\">click here</a>");
|
||||||
|
Loading…
Reference in New Issue
Block a user