<bdo id='tZq1P'></bdo><ul id='tZq1P'></ul>

        <i id='tZq1P'><tr id='tZq1P'><dt id='tZq1P'><q id='tZq1P'><span id='tZq1P'><b id='tZq1P'><form id='tZq1P'><ins id='tZq1P'></ins><ul id='tZq1P'></ul><sub id='tZq1P'></sub></form><legend id='tZq1P'></legend><bdo id='tZq1P'><pre id='tZq1P'><center id='tZq1P'></center></pre></bdo></b><th id='tZq1P'></th></span></q></dt></tr></i><div id='tZq1P'><tfoot id='tZq1P'></tfoot><dl id='tZq1P'><fieldset id='tZq1P'></fieldset></dl></div>
      1. <small id='tZq1P'></small><noframes id='tZq1P'>

      2. <tfoot id='tZq1P'></tfoot>

      3. <legend id='tZq1P'><style id='tZq1P'><dir id='tZq1P'><q id='tZq1P'></q></dir></style></legend>
      4. 正在注册的电子邮件的 PHP 检查域是“school.edu"地址

        时间:2023-09-23

          <bdo id='o9hoA'></bdo><ul id='o9hoA'></ul>
        • <tfoot id='o9hoA'></tfoot>

              <tbody id='o9hoA'></tbody>
              <legend id='o9hoA'><style id='o9hoA'><dir id='o9hoA'><q id='o9hoA'></q></dir></style></legend>
              <i id='o9hoA'><tr id='o9hoA'><dt id='o9hoA'><q id='o9hoA'><span id='o9hoA'><b id='o9hoA'><form id='o9hoA'><ins id='o9hoA'></ins><ul id='o9hoA'></ul><sub id='o9hoA'></sub></form><legend id='o9hoA'></legend><bdo id='o9hoA'><pre id='o9hoA'><center id='o9hoA'></center></pre></bdo></b><th id='o9hoA'></th></span></q></dt></tr></i><div id='o9hoA'><tfoot id='o9hoA'></tfoot><dl id='o9hoA'><fieldset id='o9hoA'></fieldset></dl></div>

                  <small id='o9hoA'></small><noframes id='o9hoA'>

                1. 本文介绍了正在注册的电子邮件的 PHP 检查域是“school.edu"地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要为一个我正在从事的项目编写一个函数,目的是为了好玩,我们正在制作一个网站,仅供学校的学生、教职员工和校友访问.

                  I need to write a function for a project i'm working on for fun, where we're making a site only accessible to students, staff, and alumni at an institution.

                  假设学校网站是:school.edu.

                  Let's say the schools website is: school.edu.

                  我在编写用于检查提交的电子邮件地址是否具有school.edu"域的 php 过滤器时遇到问题

                  I'm having trouble writing a php filter that checks that the submitted email address has the domain of "school.edu"

                  我会举一个例子.Dude #1 的电子邮件是 user@mail.com,Dude #2 的电子邮件是 user@school.edu.我想确保 Dude 1 收到错误消息,并且 Dude #2 已成功注册.

                  I'll use an example. Dude #1 has an email of user@mail.com and Dude #2 has an email at user@school.edu. I want to make sure that Dude 1 gets an error message, and Dude #2 has a successful registration.

                  这就是我想要做的事情的要点.在不久的将来,该网站将允许另外两个地区学校注册:school2.edu 和 school3.edu.然后,我需要检查器根据域的小列表(可能是数组?)来检查电子邮件,以验证电子邮件是否属于列表中的域名.

                  That's the gist of what I'm trying to do. In the near future the site will allow registration by another two locale schools: school2.edu and school3.edu. I will then need the checker to check the email against a small list (maybe an array?) of domains to verify that the email is of a domain name on the list.

                  推荐答案

                  有几种方法可以实现这一点,这里是一种:

                  There's a few ways to accomplish this, here's one:

                  // Make sure we have input
                  // Remove extra white space if we do
                  $email = isset($_POST['email']) ? trim($_POST['email']) : null;
                  
                  // List of allowed domains
                  $allowed = [
                      'school.edu',
                      'school2.edu',
                      'school3.edu'
                  ];
                  
                  // Make sure the address is valid
                  if (filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
                      // Separate string by @ characters (there should be only one)
                      $parts = explode('@', $email);
                  
                      // Remove and return the last part, which should be the domain
                      $domain = array_pop($parts);
                  
                      // Check if the domain is in our list
                      if ( ! in_array($domain, $allowed))
                      {
                          // Not allowed
                      }
                  }
                  

                  这篇关于正在注册的电子邮件的 PHP 检查域是“school.edu"地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:顶级域中的数字? 下一篇:我如何通过 PHP 知道 IP 的域?

                  相关文章

                    <i id='rs9nN'><tr id='rs9nN'><dt id='rs9nN'><q id='rs9nN'><span id='rs9nN'><b id='rs9nN'><form id='rs9nN'><ins id='rs9nN'></ins><ul id='rs9nN'></ul><sub id='rs9nN'></sub></form><legend id='rs9nN'></legend><bdo id='rs9nN'><pre id='rs9nN'><center id='rs9nN'></center></pre></bdo></b><th id='rs9nN'></th></span></q></dt></tr></i><div id='rs9nN'><tfoot id='rs9nN'></tfoot><dl id='rs9nN'><fieldset id='rs9nN'></fieldset></dl></div>
                  1. <legend id='rs9nN'><style id='rs9nN'><dir id='rs9nN'><q id='rs9nN'></q></dir></style></legend>
                  2. <small id='rs9nN'></small><noframes id='rs9nN'>

                    <tfoot id='rs9nN'></tfoot>

                      • <bdo id='rs9nN'></bdo><ul id='rs9nN'></ul>