From 9dcf9a5daae61f9d2544ee18e846c6a59c4b2501 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 10 Oct 2014 17:28:00 +0000 Subject: [PATCH] changed the way to detect https and http using x-forwarded-proto --- codepot/src/codepot/config/config.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/codepot/src/codepot/config/config.php b/codepot/src/codepot/config/config.php index e38ab2d0..d69f6b0c 100644 --- a/codepot/src/codepot/config/config.php +++ b/codepot/src/codepot/config/config.php @@ -12,7 +12,24 @@ | */ /*$config['base_url'] = "http://example.com"*/ -$config['base_url'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')? 'https': 'http'; +//$config['base_url'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')? 'https': 'http'; +if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) +{ + /* set to https if the first X-Forwarded-Proto is https */ + if (array_search ("https", array_map ('strtolower', preg_split("/[\s,]+/", $_SERVER['HTTP_X_FORWARDED_PROTO']))) === 0) + $config['base_url'] = 'https'; + else + $config['base_url'] = 'http'; +} +else if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') +{ + $config['base_url'] = 'https'; +} +else +{ + $config['base_url'] = 'http'; +} + $config['base_url'] .= "://{$_SERVER['HTTP_HOST']}"; $config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/';