Ok, It was failing every domain, so I looked around some more and figured that I needed to marry the two chunks of code, because I didn't see your code doing anything at all with the list of banned domains, so I did this:

    // check for some e-mail domains.
    list($foo, $maildomain) = split('@', $email);
    $maildomain = strtolower($maildomain);
    // get the list of banned domains
    $domains = pnConfigGetVar('reg_Illegaldomains');
    $domains = str_replace(', ', ',', $domains);

##
## Make an array of all the domain checks, separated by commas
    $checkdomains = explode(',', $domains);
##
## For each of the check domains, determine if it's a regular expression
## If it is, add it to the regexD array
## If not, add it to the chkdomains array
    foreach($checkdomains as $domain) {
##
## If the first character is "/", it must be regex (as can be predetermined by you)
        if(substr($domain, 0, 1) == '/') { $regexD[] = $domain; }
##
## Otherwise, it's just a typical domain
        else { $chkdomains[] = $domain; }
    }
    // check if our main domain is amonsgt the banned list
##
## Do a simple easy search first, see if the domain is in the typical domain list
    if (in_array($maildomain, $chkdomains)) {
       $stop = "stopped at one";
       //$stop = _EMAILINVALIDDOMAIN;
    }
##
## Now we want to loop through all our regex domains and test them
    foreach($regexD as $regex) {

##
## We use preg_match to test the regular expression against the domain
## If it's found (returns "1") then it's invalid and we can break the loop
        if ( preg_match($regex, $maildomain) != false) {
           $stop = "stopped at two";
           //$stop = _EMAILINVALIDDOMAIN;
           break;
        }
    }

Then I placed this in the banned domain list:

gawab.com,cashette.com,inmail24.net,bestboyfilms.org,etradeoil.com,mail-in.net,ukr.net,fromru.com,/.ru/,/.ua/,/.by/,/.biz/,/.info/,/.lv/,/.tv/,/.ws/

It now works again for domains, but still does not block due to TLD.

me@here.com: registered
me@here.ru registered
me@gawab.com: denied

So I've gotten back to where the regular domain check works, but I've still not got the TLD check figured out.

thanks,
json

    Hi there guys,

    I know I've probably used up all of my wishes on this thread, but I can't seem to get the regex part working. I've tried all of the testing I can think of, but I don't know what variables are supposed to be printing, so I can't tell if it's right or not, and this is my last hour of email notices:

    All are bogus, and I have to go through and individually delete them. All would have been handled by the TLD block that I'm attempting to put into place.

    I can't promise that I'll not bug you anymore after this, because it's just the way I work, but I can promise cookies shipped to your door if you'd like in return for assistance in getting it going.

    thanks,
    json

      Don't try and merge my and Brad's code. Use the separately (in place of eachother). I think Brad's is a much better implementation for your needs. So your code would be:

      // check for some e-mail domains.
          list($foo, $maildomain) = split('@', $email);
          $maildomain = strtolower($maildomain);
          // get the list of banned domains
          $domains = pnConfigGetVar('reg_Illegaldomains');
          $domains = str_replace(', ', ',', $domains);
      
      ##
      ## Make an array of all the domain checks, separated by commas
          $checkdomains = explode(',', $domains);
      
      ##
      ## Construct the regular expression:
          $regex = "/\.(?:" . implode('|', $checkdomains) . ")+$/i";
      
      ##
      ## We use preg_match to test the regular expression against the domain
      ## If it's found (returns "1") then it's invalid and we can break the loop
          if ( preg_match($regex, $maildomain) != false) {
              //$stop = "stopped at two";
              $stop = _EMAILINVALIDDOMAIN;
              break;
          }

      That should work. If not, we'll have some tweaking with the regex to work out.

      Oh, and update your banned list to be just the tlds (not the regex items like I suggested).

      Cookies are no good around here. Beer will get you farther 😉

        No cookies? Are you guys commies, or something?

        I implemented the code you posted last, and entered the following in my ban list:

        gawab.com, cashette.com, inmail24.net, bestboyfilms.org, etradeoil.com, mymail-in.net, ukr.net, fromru.com, mail.ru, bk.ru, .ru, .ua, .by, .biz, .info, .lv, .tv, .ws

        and here's my results:

        me@here.ru: allowed
        me@inbox.ru: allowed

        The first should block by TLD, and the second should block because of the domain being listed in the banlist explicitly. Both were allowed to register.

        Did I misunderstand what you meant by removing the regex? If so, that still shouldn't mess up the strict matching, should it?

        thanks,
        json

          Hi there,

          With some further testing, I have made some progress, either forward or backward:

          removing the periods from the list of banned tlds, I ended up with this:

          ru, biz, by, info, in, lv, tv, ws

          When I attempted to register with a .ru mail domain, I got the following:

          Fatal error: Cannot break/continue 1 level in /home/husaberg/public_html/modules/NewUser/user.php on line 299

          Line 299 is:

          break;
          

          in the code posted above.

          Unless I'm mistaken, it seems like it tried to stop the registration, but had a problem breaking out, no?

          thanks,
          json

            Remove the "break;" line as it's not needed anymore. That was a mistake upon my part.

            Okay, so you have two different types of items in your "check domains" array. So your choices are:

            1.) Do not include the "." in the listing of disallowed domains and use the above regex

            2.) Include the "." in the listing of disallowed domains and use the following regex:

            $regex = "/(?:" . implode('|', $checkdomains) . ")+$/i";

            Hope that helps.

              Hi there Brett,

              It works! I removed the break, and it blocks mail domains ending the the list I created.

              I wanted to be able to block both by strict matches and by TLD, so what I did is restore the original match function that was on the site originally, then(since I won't be adding/removing from the list often) added the function you created separately, defining the list of TLD's inline.

              It now blocks by strict match, and also blocks by TLD.

              I can't thank you enough for your help. If you'll pm me your addy, I'll gladly send some primo suds to your doorstep.

              Maybe Brad would like the cookies, as I don't think he's of legal drinking age yet, is he?

              thanks again for everything, guys,
              json

                That's okay, I'm floating in beer here as it is 😉 The annual Crab Feast is this weekend!! I'll make sure I tip a glass for you 🙂 🙂

                Glad to hear you got it sorted. Here's a bit of test-code I got working for me. Works from what i can tell 😉 Might even be able to replace that "strict" block.

                $domains = str_replace(', ', ',', 'gawab.com, cashette.com, inmail24.net, bestboyfilms.org, etradeoil.com, mymail-in.net, ukr.net, fromru.com, mail.ru, bk.ru, .ru, .ua, .by, .biz, .info, .lv, .tv, .ws');
                $checkdomains = explode(',', $domains);
                
                $regex = '/(?:' . implode('|', $checkdomains) . ')+$/i';
                
                $domains = array('allowed'=>array('there.aw', 'microsoft.com', 'roundcube.net', 'actionsoptions.org', 'tvtorrents.com'),
                				'disallowed'=>array('here.ru', 'etradeoil.com', 'mymail-in.net', 'cashette.com', 'last.tv')
                			);
                
                foreach($domains as $type=>$domain)
                {
                	echo '<h3>' . ucwords($type) . ' Domains</h3>';
                	foreach($domain as $d)
                	{
                		echo $d . ' ... ';
                		if(preg_match($regex, $d) == true)
                		{
                			echo '<span style="color: #900;">BLOCKED</span>';
                		}
                		else
                		{
                			echo '<span style="color: #090;">ALLOWED</span>';
                		}
                		echo '<br />';
                	}
                }
                  schwim wrote:

                  Maybe Brad would like the cookies, as I don't think he's of legal drinking age yet, is he?

                  I just got back from a float trip down the Meramec River in Missouri with the guys from my soon-to-be fraternity, so... eh... I mean no, of course I don't drink yet! 🙂

                    soon-to-be fraternity

                    Not to throw swords, but I always wondered why people would pay to have friends 😛

                      Hi there Brett,

                      Thanks very much for the code. I'm going to play with it, as I would like to be able to block registrations by certain text in their user info(like viagra, cialis, etc.)

                      If I can ask, how would the regex statement differ if I wanted to check for the text anywhere in the data, and no longer just at the end of the string?

                      For instance:

                      Viagra is cool
                      My Viagra rocks
                      Ask me about my Viagra

                      Would all trigger the match?

                      @: (wink, wink), I understand that you in no way partake of libations 😃

                      thanks,
                      json

                        json:

                        The difference would be the "$" that appears in it.

                        However, if you're just looking to see if a word appears inside of a block of text, use [man]strpos/man to do that. That's not just from me, the preg_match and eregi entries say that 😉

                          bpat1434 wrote:

                          Not to throw swords, but I always wondered why people would pay to have friends 😛

                          Pay? Living w/ the fraternity would be cheaper than the dorms, has better living conditions, better food :p, better atmosphere, and access to materials from an engineer in my field who's already taken the classes I'm taking.

                            Write a Reply...