Skip to content

Instantly share code, notes, and snippets.

@w3guy
Created October 7, 2013 09:03
Show Gist options
  • Save w3guy/23d700e94a300c42fee2 to your computer and use it in GitHub Desktop.
Save w3guy/23d700e94a300c42fee2 to your computer and use it in GitHub Desktop.
Protecting Your PHP Web App From Disposable Email Users via DEA-filter http://w3guy.com/protect-php-app-disposable-email/
<?php
function checkDEAfilter($deaEmailToCheck)
{
$apiKey = "5a8047b40e57750726618b8146066ef6"; // change to your API key
$curlPost = "mail=" . $deaEmailToCheck."&key=".$apiKey; //address to check
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.deafilter.com/classes/DeaFilter.php"); //must point to the DeaFilter.php class
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
curl_setopt($ch, CURLOPT_VERBOSE,0);
$data = curl_exec($ch);
curl_close($ch);
$data = json_decode($data);
if ($data->result != "ok")
{
return false;
} else
{
return true;
}
}
<?php include "deaFilterClient.php";?>
<form action="" method="post">
<label for="male">Email Address</label><br/>
<input type="text" name="email" id="email" value="<?php echo (isset($_POST["email"])) ? $_POST["email"] : "";?>"/>
<?php
// validate and detect if email is disposable or not
if (isset($_REQUEST["email"]))
{
if ( !checkDEAfilter($_REQUEST["email"])) {?>
<img src="images/cancel.png"/> &nbsp; &nbsp; <input type="submit" value="validate"/> <?php }
else echo '<img src="images/accept.png"/>';} else echo '<input type="submit" value="validate"/>';
?>
<br/><br/>
<input type="submit" name="submit" value="submit form"/>
</form>
// validate the form before sent to the server for processing
// Check if email is set and if it not disposable
<?php if((isset($_REQUEST["submit"])) && (checkDEAfilter($_REQUEST["email"]))) {
echo "your email is " . $_REQUEST['email'] ;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment