...

View Full Version : Deny certain email domains?



student101
05-09-2008, 12:07 PM
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
$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
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;
}
?>

rafiki
05-09-2008, 12:10 PM
Does none of them snippets work? have you tried them?

student101
05-09-2008, 12:19 PM
That's a great question, not sure how to with the function thingy.

Cheers

rafiki
05-09-2008, 12:27 PM
Hehe you made a function and not sure how to use it.

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


$email = $_POST['email'];
custom_emailblacklist($email);
try using explode (http://www.php.net/manual/en/function.explode.php).

student101
05-09-2008, 12:36 PM
You have opened my eyes :eek: :D
Now I need to figure out how this could work with the rest of my validation.

<?php
$db = connect to db part, blah blah.
//================Validate the Username=================
// validateUsername
//================Validate the email address=================
// validateEmail
//================Validate the Domain=================
// validateDomain
?>

student101
05-09-2008, 01:13 PM
So I would have to split the email address before I validate it.

$addr = explode("@", $email);
echo $addr;
But it aint working out, all I get is Array?

Ok got it with this one:

$emailadd = explode("@", $email);
echo $emailadd[1];

student101
05-09-2008, 01:53 PM
Hehe you made a function and not sure how to use it.
try using explode (http://www.php.net/manual/en/function.explode.php).
Thank you, rafiki

rafiki
05-09-2008, 01:57 PM
Your welcome.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum