PHP-检测HTTPS协议(protocol)的一些问题

标签 php jquery

我在加载模板时遇到问题,我尝试在 XAMPP 上测试我的模板,但同样的问题再次发生

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at admin@main-hosting.eu to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.`

一开始它没有显示任何内容,只是加载页面,然后错误就不再出现了...请帮忙,但在 XAMPP 上它只是不断加载我的页面 但过了一段时间,当我试图解决问题时,找到了它并尝试解决它,但我需要一些帮助来修复之前导致它的代码

$Domain = $_SERVER['HTTP_HOST'];
$Path = $_SERVER['PHP_SELF'];   
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) 
{
    echo '<script type="text/javascript">window.location.assign("https://' .$Domain.$Path. '");</script>';
} 
else 
{
    echo '<script type="text/javascript">window.location.assign("http://' .$Domain.$Path. '");</script>';
}

请帮忙???

最佳答案

原因是因为每次加载页面时脚本都会运行并不断刷新网站。您需要知道页面是否已被重定向。 示例:

<?php
    if (!isset($_GET['r'])){
        $Domain = $_SERVER['HTTP_HOST'];
        $Path = $_SERVER['PHP_SELF'];   
        if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) 
        {
            echo '<script type="text/javascript">window.location.assign("https://' .$Domain.$Path. '?r=https");</script>';
        } 
        else 
        {
            echo '<script type="text/javascript">window.location.assign("http://' .$Domain.$Path. '?r=http");</script>';
        }
    }
 ?>

我不明白这一点。我建议您改用位置。示例:

header('Location: http://www.example.com/');

关于PHP-检测HTTPS协议(protocol)的一些问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44515522/

相关文章:

php - 如何将用户输入的换行符保存到数据库。 (jQuery/php/mysql)

php - 在 codeigniter 中使用 Order By

javascript - 根据里面的内容使 iframe 高度动态化 - JQUERY/Javascript

jQuery 将 css left 设置为值 1,完成后设置为值 2?

javascript - 无法使 HTML 在 jquery 中可见

javascript - getElementsByClassName 不是函数 javascript

php - 是否有用于 PHP 的 identicon 库

php - 使用 html_entity_decode 转换特殊字符不起作用

javascript - 否则无法在 JavaScript 中工作

php - 弹出表单ajax请求不起作用