mirror of
https://github.com/disposable-email-domains/disposable-email-domains.git
synced 2024-11-26 10:38:12 +08:00
More efficient PHP code based on original
- $path defined so the code works from anywhere in a framework folder structure - file is loaded to an “associative array” instead of a standard array. The prior approach had to search through entire array to find email address. This approach can use the key index.
This commit is contained in:
parent
170d0826ca
commit
a8d1242292
14
README.md
14
README.md
@ -31,14 +31,16 @@ Available as [PyPI module](https://pypi.python.org/pypi/disposable-email-domains
|
|||||||
True
|
True
|
||||||
```
|
```
|
||||||
|
|
||||||
**PHP** contributed by @txt3rob and @deguif
|
**PHP** contributed by [@txt3rob](https://github.com/txt3rob), [@deguif](https://github.com/deguif) and [@pjebs](https://github.com/pjebs)
|
||||||
```php
|
```php
|
||||||
function is_temp_mail($mail) {
|
function is_disposable_email($email) {
|
||||||
$mail_domains_ko = file('disposable_email_blacklist.conf', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
$path = realpath(dirname(__FILE__)) . '/disposable_email_blacklist.conf';
|
||||||
|
$mail_domains_ko = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
//Need to ensure the mail contains an @ to avoid undefined offset
|
$mail_domains_ko = array_combine($mail_domains_ko, array_fill(0,count($mail_domains_ko), null));
|
||||||
return in_array(explode('@', $mail)[1], $mail_domains_ko);
|
$domain = mb_strtolower(explode('@', trim($email))[1])
|
||||||
|
return (isset($mail_domains_ko[$domain]) || array_key_exists($domain, $mail_domains_ko));
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
**Ruby on Rails** contributed by @MitsunChieh
|
**Ruby on Rails** contributed by @MitsunChieh
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user