Https引起太多重定向?

I have a simple code in place for my php file to redirect to https if it's not present and I keep getting a too many redirects issue.

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

Is there something I can do to fix the issue?

Thank you.

From PHP manual, $_SERVER['HTTPS'] is Set to a non-empty value if the script was queried through the HTTPS protocol. That isn't necessarily on. You may then end up in an infinite loop of redirects.

To avoid this, use the empty() function:

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

Note: Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol.

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