Block certain email users / IPs from signing up with PHP explode
April 25, 2010
Often, we ask visitors to fill forms on our portals. As a measure to prevent ‘System Abuse’ from users with email accounts from free email providers, many forums and websites bar users with such mail IDs from signing-up for their services.
The following PHP script will do the same for your websites.
| $emailadd = explode(“@”, $email); | //spilts string in ‘email’after ‘@’ and puts the result in ‘emailadd’ |
| echo $emailadd[1]; | |
| $mailchk=”SELECT * FROM reposit WHERE email=’$emailadd’”;
$answer=mysql_query($mailchk); |
//this lines will check if ‘emailadd’ exists in the table ‘reposit’ of the database |
| $mcount=mysql_num_rows($answer); | //’mcount’ will have the number of rows in which the domain-name exists in ‘reposit’ |
| if($mcount==1){
echo “You cannot use this mail account”; { whatever action you want } |
//if an entry for the domain-name specified in ‘emailadd’ exists, the if-else is executed accordingly |
Description of explode:
explode(separator, string, limit)
separator - Required. Specifies where to break the string
string – Required. The string to split
limit – Optional. Specifies the maximum number of array elements to return
Note:
- This method will require a database that will contain entries of all the email providers that you wish to add
- See to it that while making entries in this database, you do not add an entry more than one time, else the code if($mcount==1) will not work. (You may refine the code to >= 1, but haven’t tried it)
- Same code can be used to allow or block IP addresses by specifying the separator as ‘.’ (dot). The splitted strings can be stored in an array.
Advertisement