gpt4 book ai didi

php - Apache PHP 5 header() 问题 SSL 域

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:40:14 26 4
gpt4 key购买 nike

我想知道以前是否有人遇到过这个问题,您是否知道如何解决这个问题。基本上我有一个 SSL 加密的页面,还有一些没有/不能加密的页面(由于插件依赖性)所以在没有 SSL 的页面上我检测到一个 header 并尝试重定向到 HTTP 版本页面:

if($_SERVER["HTTPS"] == "on")
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com");
exit();
}

但是 PHP 似乎阻止我从安全域重定向到同一域的非安全站点!

如果我从 https://www.example.com -> <a href="http://www.secondsite.com" rel="noreferrer noopener nofollow">http://www.secondsite.com</a>它有效但是,https://www.example.com -> <a href="http://www.example.com" rel="noreferrer noopener nofollow">http://www.example.com</a>迫使我留在加密网站上并导致无休止的重定向。

有什么建议吗??

瑞克

最佳答案

您也许可以确保您的 header 尚未发送,这可能是保持在同一页面上的情况。从 php 手册中看到这个:

function redirect($url, $debug=FALSE){

// If headers not sent yet... then do php redirect
if (!headers_sent()) {
header('Location: '.$url);
exit;
// if headers are already sent... do javascript redirect... if javascript is disabled, do html redirect.
} else {

// Js redirect
echo '<script type="text/javascript">';
echo "<!--";
echo 'window.location.href="'. $url .'";';
echo "//-->";
echo '</script>';

// HTML redirect if js disabled
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>';
}
}//==== End -- Redirect

关于php - Apache PHP 5 header() 问题 SSL 域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6494392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com