使用程序(ASP/PHP)强制跳转到HTTPS

莫南 | |被浏览38次| -1
|2018-05-28 22:46:26

(ASP/PHP) 跳转到HTTPS

满意回答

2018-05-28 22:46:27

兼容:


<!-- 如果检测到是http页面,则自动跳转到对应的https页面 -->
<script type="text/javascript">
if (document.location.protocol != "https:") {
        location.href = location.href.replace(/^http:/,"https:");
}
</script>




ASP:

<%
If Request.ServerVariables("SERVER_PORT")=80 Then
Dim strSecureURL
strSecureURL = "https://"
strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
strSecureURL = strSecureURL & Request.ServerVariables("URL")
Response.Redirect strSecureURL
End If
%>




PHP:


if(!isset($_SERVER['HTTPS'])||!$_SERVER['HTTPS']){
$url ='https://'. $_SERVER['HTTP_HOST']. $_SERVER['REQUEST_URI'];
header('Location: '. $url);exit;
}

一生二

 |采纳率:64%

您需要登录后才可以回复

全部回答(1)

  • 2018-05-28 22:46:27

    兼容:








    ASP:

    <%
    If Request.ServerVariables("SERVER_PORT")=80 Then
    Dim strSecureURL
    strSecureURL = "https://"
    strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
    strSecureURL = strSecureURL & Request.ServerVariables("URL")
    Response.Redirect strSecureURL
    End If
    %>




    PHP:


    if(!isset($_SERVER['HTTPS'])||!$_SERVER['HTTPS']){
    $url ='https://'. $_SERVER['HTTP_HOST']. $_SERVER['REQUEST_URI'];
    header('Location: '. $url);exit;
    }

一个提问,一份期待;一条回答,一份回应。知识问与答,连接你和我!

-- 来自问答管理员 admin

返回顶部