php 判断http还是https,以及获得当前url的方法
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
echo $http_type . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
1、php判斷http請求還是https請求
?? ?/**
? ? ?* PHP判斷當前協議是否為HTTPS
? ? ?*/
?? ?function is_https() {
?? ? ? ?if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
?? ? ? ? ? ?return true;
?? ? ? ?} elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
?? ? ? ? ? ?return true;
?? ? ? ?} elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
?? ? ? ? ? ?return true;
?? ? ? ?}
?? ? ? ?return false;
?? ?}
?
調用:
$http_type = $this->is_https();
if($http_type){
echo "是https";
}else{
echo "是http";
}
?
?
2、 js判斷http請求還是https請求
var ishttps = 'https:' == document.location.protocol ? true: false;
if(ishttps){
alert('https');
}else{
alert('http');
}
來源:https://blog.csdn.net/haibo0668/article/details/81113133
轉載:https://blog.csdn.net/ghostyusheng/article/details/53581825
https://blog.csdn.net/u010073893/article/details/53639218#
總結
以上是生活随笔為你收集整理的php 判断http还是https,以及获得当前url的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 把关人理论名词解释(把关人理论)
- 下一篇: php解析url并得到url中的参数及获