Remove dots "." and plus "+" before add item/account from user e-mail
on :February 15, 2023, 4:28 pm #673
How to remove the dots and the "plus" sign from the email before saving to the database in osclass?
I have a spammer on the site. He uses 1 email address with "." and "+" to create accounts e.g:
spamer@gmail.com
s.p.a.me.r@gmail.com
or
spamer+1@gmail.com
spamer+13sdf@gmail.com
He just adds "." or "+" to the email address and osclass creates a new account every time, or adds a new ad without registration. I would like to block this.
The idea is that for "google.com" accounts, when a user registers, remove ALL dots and plus signs and keep a clean address in the database.
I tried to do something with hook "pre_item_add"
file: function.php
function dh_before_add($aItem){
$aItem['contactName'] = 'newEmail@xxxx.com';
return $aItem;
}
osc_add_hook('pre_item_add', 'dh_before_add',0);
But it do nothing :/
Any help?
Re: Remove dots
on :February 15, 2023, 6:45 pm #674
I don't think that just removing the dots and plus signs will solve your issue.
Here you have a code that removes that but this will not solve your issue with new items.
function change_email_on_post($aItem) {
$email = $aItem['contactEmail'];
if (!empty($email)) {
$explode = explode('@', $email);
if ($explode[1] == 'gmail.com') {
$pattern = array('+', '.');
$aItem['contactEmail'] = str_replace($pattern, '', $explode[0]) .'@'. $explode[1];
}
}
return $aItem;
}
osc_add_filter('item_add_prepare_data', 'change_email_on_post');
You need another form of blocking based on IP or clicks, I have a plugin for that. Or you can activate the publish for logged users.
Re: Remove dots
on :February 20, 2023, 4:00 pm #676
Hi
I have tested your code - it work fine for me. I have "Anti Spam & Protection System" plugin and adding this code it is doing good job.
Re: Remove dots
on :February 20, 2023, 4:01 pm #677
Thank you for that!
Re: Remove dots
on :March 2, 2023, 2:33 pm #685
My latest version of code should look like this.
It will remove dost and + and it will return oryginal "mail name" without postfix, e.g.
mailName@gmail.com => mailName@gmail.com
mai.lNa.m.e@gmail.com => mailName@gmail.com
mailName+helloKitty => mailName@gmail.com
ma.il.N.a.m.e+h.el.l.o.K.i..t.ty => mailName@gmail.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function change_email_on_post($aItem) {
$email = $aItem['contactEmail'];
if (!empty($email)) {
$explode = explode('@', $email);
if ($explode[1] == 'gmail.com') {
$mailName = $explode[0];
//remove everythings after + sign, eg. adresEmali+SPAM
if (strpos($mailName, '+') !== false) {
$beforePlus = explode('+', $mailName);
$explode[0] = $beforePlus[0];
}
$pattern = array('.');
$aItem['contactEmail'] = str_replace($pattern, '', $explode[0]) .'@'. $explode[1];
}
}
return $aItem;
}
osc_add_filter('item_add_prepare_data', 'change_email_on_post');