服务器上的时间不匹配 - php 中的双因素身份验证

Time mismatched on servers - Two factor authentication in php

我在 PHP 中使用 google 身份验证器创建了双因素身份验证。它在我的本地主机上运行良好,但在我的网站上生成的代码不匹配。我发现这是一个时间配置问题。帮我设置双因素时间。

public function verifyCode($secret, $code, $discrepancy = 1, $currentTimeSlice = null)
{
    if ($currentTimeSlice === null) {
        $currentTimeSlice = floor(time() / 30);
    }

    for ($i = -$discrepancy; $i <= $discrepancy; $i++) {
        $calculatedCode = $this->getCode($secret, $currentTimeSlice + $i);
        if ($calculatedCode == $code ) {
            return true;
        }
    }

    return false;
}

很可能是网络服务器上的时间漂移​​。确保 Web 服务器上的时间正确且准确 (UTC)。