如何验证用户是否来自我的 6 个域之一

How to verify a user is from one of my 6 domains

本文关键字:我的 自我 是否 何验证 验证 用户      更新时间:2023-09-26
<script type="text/javascript">
  function onSignIn(googleUser) {
                var profile = googleUser.getBasicProfile();
                console.log("ID: " + profile.getId()); 
                console.log("Email: " + profile.getEmail());
                var id_token = googleUser.getAuthResponse().id_token;
                console.log("ID Token: " + id_token);
                if(id_token !="")
                {
                 window.location = 'support.php';
                }
              };
</script>

我已经做了相当多的搜索,似乎找不到我要找的东西。上面的代码是我所拥有的。我需要它做的是以下内容。

我有 6 个域访问同一个网站。我想拥有它,以便只有这六个谷歌域可以登录。如果您的电子邮件与六个域之一不匹配,它将带您进入错误页面。我该怎么做?任何帮助将不胜感激。

如果你真的在寻找PHP而不是javascript,那么这样的东西应该可以工作:

$email = $_POST['email'];
$allowed = array('domain1.com', 'domain2.com', 'domain3.com');
// Make sure the address is valid
if (filter_var($email, FILTER_VALIDATE_EMAIL))
{
    $explodedEmail = explode('@', $email);
    $domain = array_pop($explodedEmail);
    if ( ! in_array($domain, $allowed))
    {
        // Not allowed
        header('Location: http://example.com/myOtherPage.php');
    }
}