Determine http request or https request
Others
2022-04-27 23:06:34
views: 0
1. PHP judges http request or https request
- $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
- var ishttps = 'https:' == document.location.protocol ? true: false;
- if(ishttps){
- alert('https');
- }else{
- alert('http');
- }
3. js judges the mobile terminal and the PC terminal
- <SCRIPT type=text/javascript>
-
- try {
- var urlhash = window.location.hash;
- if (!urlhash.match("fromapp"))
- {
- var ishttps = 'https:' == document.location.protocol ? 'https://': 'http://';
-
-
- if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
- {
- window.location= ishttps+"www.baidu.com/share.html";
- }
-
- if((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)) && (/MicroMessenger/i.test(navigator.userAgent))){
- window.location= ishttps+"www.baidu.com/share.html";
- }
- }
- }
- catch(err)
- {
- }
- </SCRIPT>
Origin http://43.154.161.224:23101/article/api/json?id=325906784&siteId=291194637