Determine http request or https request

1. PHP judges http request or https request

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


2. js judges http request or https request

[javascript]  view plain copy  
  1. var ishttps = 'https:' == document.location.protocol ? truefalse;  
  2. if(ishttps){  
  3. alert('https');  
  4. }else{  
  5. alert('http');  
  6. }  

3. js judges the mobile terminal and the PC terminal

[javascript]  view plain copy  
  1. <SCRIPT type=text/javascript>  
  2.     //uaredirect("/vida/xinfeng/mobi/moshare/share.html");  
  3.     try {  
  4.         var urlhash = window.location.hash;  
  5.         if (!urlhash.match("fromapp"))  
  6.         {  
  7.             var ishttps = 'https:' == document.location.protocol ? 'https://''http://';  
  8.             //console.log(document.location.protocol);  
  9.             //console.log(ishttps);  
  10.             if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))  
  11.             {  
  12.                 window.location= ishttps+"www.baidu.com/share.html";  
  13.             }  
  14.   
  15.             if((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)) && (/MicroMessenger/i.test(navigator.userAgent))){  
  16.                window.location= ishttps+"www.baidu.com/share.html";  
  17.             }  
  18.         }  
  19.     }  
  20.     catch(err)  
  21.     {  
  22.     }  
  23. </SCRIPT>  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325906784&siteId=291194637