Topic: Restricting email addresses
Hi, I thought I might just make a quick note here in case it's useful to anyone. I need to restrict registrations to one of a set of pre-defined email addresses. This is for a site that is being run for University classes.
In config.php, add (for example):
$email_whitelist = array(
"uts.edu.au",
"eecs.berkeley.edu"
);
In lang/English/common.php, add:
'Unlisted e-mail' => 'This email address does not match the list of valid email suffixes. Please post in the login help forum if you believe this is an error.',
In register.php, after:
if (!is_valid_email($email1))
message($lang_common['Invalid e-mail']);
add:
else if (!is_email_whitelisted($email1))
message($lang_common['Unlisted e-mail']);
And in include/email.php, add:
//
// Check if an email address is whitelisted
//
function is_email_whitelisted($email) {
global $email_whitelist;
foreach ($email_whitelist as $p) {
$p1 = ereg_replace('\.', '\\.', $p);
$p2 = '^[^@]+@' . $p1 . '$';
$p3 = '^[^@]+@[^@]+\.' . $p1 . '$';
if (eregi($p2, $email) || eregi($p3, $email))
return true;
}
return false;
}
Only tested quickly but it seems to work. Thanks
JohnR