Https引起太多重定向?

时间:2013-04-21 18:52:54

标签: php loops redirect https

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

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

我有什么办法可以解决这个问题吗?

谢谢。

2 个答案:

答案 0 :(得分:3)

来自PHP manual$_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');
}
  

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

答案 1 :(得分:1)

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