Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question Deny certain email domains?

    How would I be able to deny users with certain email domains from registering.

    Example:
    A User has yahoo, gmail or webmail accounts.
    They want to register with one of these emails on the site but the site does not allow "email@ yahoo.com", "email@ gmail.com" and so on.

    What am I looking at doing to get this done?
    Pure PHP, .htaccess or something else

    Here is some dummy code to help understand what I mean.
    PHP Code:
    <?php 
    $domain 
    substr(strrchr($email"@"), 1);
    $baned_domains = array('yahoo.net''yahoo.com''gmail.com''google.com''and so on...');
    if (
    in_array($domain$baned_domains)){
    $msg 'Your email address is not allowed. Please re-submit with an alternate address.';
    }
    ?>
    PHP Code:
    <?php 
    function custom_emailblacklist($email)
    {
        
    $blocking = Array( 'yahoo.net''yahoo.com''gmail.com''google.com''and so on...');
        foreach (
    $blocking as $addr) {
           if (
    strpos($email$addr) !== FALSE) {
                
    accessLog("tried to register $email");
                return 
    TRUE;
            }
        }
        return 
    FALSE;
    }
    ?>
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Does none of them snippets work? have you tried them?

  • #3
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    That's a great question, not sure how to with the function thingy.

    Cheers
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Hehe you made a function and not sure how to use it.
    PHP Code:
    function custom_emailblacklist($email)
    {
        
    $blocking = Array( 'yahoo.net''yahoo.com''gmail.com''google.com''and so on...');
        foreach (
    $blocking as $addr) {
           if (
    strpos($email$addr) !== FALSE) {
                
    accessLog("tried to register $email");
                return 
    TRUE;
            }
        }
        return 
    FALSE;

    then call it in the php script like
    PHP Code:
    $email $_POST['email'];
    custom_emailblacklist($email); 
    try using explode.

  • Users who have thanked rafiki for this post:

    student101 (05-09-2008)

  • #5
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    You have opened my eyes
    Now I need to figure out how this could work with the rest of my validation.
    PHP Code:
    <?php 
    $db 
    connect to db partblah blah.
    //================Validate the Username=================
    // validateUsername
    //================Validate the email address=================
    // validateEmail
    //================Validate the Domain=================
    // validateDomain
    ?>
    Last edited by student101; 05-10-2008 at 05:31 PM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #6
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    So I would have to split the email address before I validate it.
    PHP Code:
    $addr explode("@"$email);
    echo 
    $addr
    But it aint working out, all I get is Array?

    Ok got it with this one:
    Code:
    $emailadd = explode("@", $email);
    echo $emailadd[1];
    Last edited by student101; 05-09-2008 at 02:32 PM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #7
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by rafiki View Post
    Hehe you made a function and not sure how to use it.
    try using explode.
    Thank you, rafiki
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #8
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Your welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •