PHP和JS判断来源是http请求还是https请求

xiaoxiao2021-02-28  97

1、php判断http请求还是https请求

[php]  view plain  copy $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';  

2、 js判断http请求还是https请求

[javascript]  view plain  copy var is_https = 'https:' == document.location.protocol ? truefalse;   if(is_https){      alert('https');   }else{      alert('http');   }  

3、js判断手机端和PC端

[javascript]  view plain  copy <SCRIPT type=text/javascript>       try {           var urlhash = window.location.hash;           if (!urlhash.match("fromapp"))           {               var httpsPrefix= 'https:' == document.location.protocol ? 'https://''http://';               //console.log(document.location.protocol);               //console.log(ishttps);               if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))               {                   window.location= httpsPrefix+"www.baidu.com/share.html";               }                  if((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)) && (/MicroMessenger/i.test(navigator.userAgent))){                  window.location= httpsPrefix+"www.baidu.com/share.html";               }           }       }       catch(err) {   }   </SCRIPT>  
转载请注明原文地址: https://www.6miu.com/read-44153.html

最新回复(0)