Last active
April 2, 2023 06:07
-
-
Save Barneybook/6bc0a9a6e6056b08d89553648ef12dd3 to your computer and use it in GitHub Desktop.
Codeigniter base_url setting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// false | |
$root = ($_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http'); | |
// false | |
$root = "http".((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : ""); | |
// false | |
$root = (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) === 'off') ? 'http' : 'https'; | |
// can use | |
$isSecure = false; | |
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { | |
$isSecure = true; | |
} | |
elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { | |
$isSecure = true; | |
} | |
$root = $isSecure ? 'https' : 'http'; | |
$root .= "://" . $_SERVER['HTTP_HOST']; | |
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']); | |
$config['base_url'] = "$root"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> | |
</head> | |
<body> | |
<h1>#SSL TEST PAGE#</h1> | |
<p>This page is used purely to test for SSL availability.</p> | |
<?php | |
$ssl = FALSE; | |
if (isset($_SERVER['HTTPS'])) { | |
if (strtolower($_SERVER['HTTPS']) == 'on') { | |
echo "#SERVER-HTTPS-ON#" . " (" . htmlentities($_SERVER['HTTPS'], ENT_QUOTES, 'UTF-8') . ")<br>"; | |
$ssl = TRUE; | |
} | |
if ('1' == $_SERVER['HTTPS']) { | |
echo "#SERVER-HTTPS-1#<br>"; | |
$ssl = TRUE; | |
} | |
} | |
if (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) { | |
echo "#SERVERPORT443#<br>"; | |
$ssl = TRUE; | |
} | |
if (isset($_ENV['HTTPS']) && ('on' == $_ENV['HTTPS'])) { | |
echo "#ENVHTTPS#<br>"; | |
$ssl = TRUE; | |
} | |
if (!empty($_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO']) && ($_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'] == 'https')) { | |
echo "#CLOUDFRONT#<br>"; | |
$ssl = TRUE; | |
} | |
if (!empty($_SERVER['HTTP_CF_VISITOR']) && (strpos($_SERVER["HTTP_CF_VISITOR"], "https") !== false)) { | |
echo "#CLOUDFLARE#<br>"; | |
$ssl = TRUE; | |
} | |
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) { | |
echo "#LOADBALANCER#<br>"; | |
$ssl = TRUE; | |
} | |
if (!empty($_SERVER['HTTP_X_PROTO']) && ($_SERVER['HTTP_X_PROTO'] == 'SSL')) { | |
echo "#HTTP_X_PROTO#<br>"; | |
$ssl = TRUE; | |
} | |
if (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && ($_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')) { | |
echo "#HTTP_X_FORWARDED_SSL_ON#<br>"; | |
$ssl = TRUE; | |
} | |
if (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && ($_SERVER['HTTP_X_FORWARDED_SSL'] == '1')) { | |
echo "#HTTP_X_FORWARDED_SSL_1#<br>"; | |
$ssl = TRUE; | |
} | |
if ($ssl) { | |
echo "<br>#SUCCESSFULLY DETECTED SSL#"; | |
} else { | |
echo "<br>#NO KNOWN SSL CONFIGURATION DETECTED#"; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/1175096/how-to-find-out-if-youre-using-https-without-serverhttps
補上自己查到更完整的一篇說明