繁体   English   中英

Https引起太多重定向?

[英]Https causing too many redirects?

我有一个简单的代码,我的PHP文件重定向到https,如果它不存在,我不断收到太多重定向问题。

if(strtolower($_SERVER['HTTPS']) != 'on') {
redirect('https://domain.com/register.php');
}

我能做些什么来解决这个问题吗?

谢谢。

Set to a non-empty value if the script was queried through the HTTPS protocol.$_SERVER['HTTPS'] PHP手册 Set to a non-empty value if the script was queried through the HTTPS protocol. $_SERVER['HTTPS'] Set to a non-empty value if the script was queried through the HTTPS protocol. 这不一定on 然后,您可能会进入无限循环的重定向。

要避免这种情况,请使用empty()函数:

if ((!isset($_SERVER['HTTPS'])) || (empty($_SERVER['HTTPS']))
{
    redirect('https://domain.com/register.php');
}

注意:请注意,将ISAPI与IIS一起使用时,如果请求不是通过HTTPS协议进行的,则该值将关闭。

if(!isset($_SERVER['HTTPS'])){
 //redirect
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM