Jump to content
MakeWebGames

Awesome 1st step to email validation.


Phases
 Share

Recommended Posts


Test for Manuel Lemos's PHP E-mail validation class



<?php
require("email_validation.php");

$validator=new email_validation_class;

/*
* If you are running under Windows or any other platform that does not
* have enabled the MX resolution function GetMXRR() , you need to
* include code that emulates that function so the class knows which
* SMTP server it should connect to verify if the specified address is
* valid.
*/
if(!function_exists("GetMXRR"))
{
/*
* If possible specify in this array the address of at least on local
* DNS that may be queried from your network.
*/
$_NAMESERVERS=array();
include("getmxrr.php");
}
/*
* If GetMXRR function is available but it is not functional, you may
* use a replacement function.
*/
/*
else
{
$_NAMESERVERS=array();
if(count($_NAMESERVERS)==0)
Unset($_NAMESERVERS);
include("rrcompat.php");
$validator->getmxrr="_getmxrr";
}
*/

/* how many seconds to wait before each attempt to connect to the
   destination e-mail server */
$validator->timeout=10;

/* how many seconds to wait for data exchanged with the server.
   set to a non zero value if the data timeout will be different
than the connection timeout. */
$validator->data_timeout=0;

/* user part of the e-mail address of the sending user
   ([email protected] in this example) */
$validator->localuser="info";

/* domain part of the e-mail address of the sending user */
$validator->localhost="phpclasses.org";

/* Set to 1 if you want to output of the dialog with the
   destination mail server */
$validator->debug=1;

/* Set to 1 if you want the debug output to be formatted to be
displayed properly in a HTML page. */
$validator->html_debug=1;


/* When it is not possible to resolve the e-mail address of
   destination server (MX record) eventually because the domain is
   invalid, this class tries to resolve the domain address (A
   record). If it fails, usually the resolver library assumes that
   could be because the specified domain is just the subdomain
   part. So, it appends the local default domain and tries to
   resolve the resulting domain. It may happen that the local DNS
   has an * for the A record, so any sub-domain is resolved to some
   local IP address. This  prevents the class from figuring if the
   specified e-mail address domain is valid. To avoid this problem,
   just specify in this variable the local address that the
   resolver library would return with gethostbyname() function for
   invalid global domains that would be confused with valid local
   domains. Here it can be either the domain name or its IP address. */
$validator->exclude_address="";

if(IsSet($_GET["email"]))
$email=$_GET["email"];
if(IsSet($email)
&& strcmp($email,""))
{
if(($result=$validator->ValidateEmailBox($email))<0)
echo "

It was not possible to determine if $email is a valid deliverable e-mail box address.
\n";
else
echo "

$email is ".($result ? "" : "not ")."a valid deliverable e-mail box address.
\n";
}
else
{
$port=(strcmp($port=getenv("SERVER_PORT"),"") ? intval($port) : 80);
$site="http://".(strcmp($site=getenv("SERVER_NAME"),"") ? $site : "localhost").($port==80 ? "" : ":".$port).GetEnv("REQUEST_URI");
echo "

Access this page using a URL like: $site?email=[email protected]

\n";
}
?>


Link to comment
Share on other sites

Re: Awesome 1st step to email validation.

That's interesting... I don't have DNS.php either.

Sorry - I felt the file descriptions at the top were sufficient for what to do...

First File:  email_validation.php - This is the actual class that checks the email address - put this in your class folder.

Second File: getmxrr.php - you probably won't need this one, I didn't.  I is a replacement function if your PHP was compiled w/o getmxrr.  If you need it, I'd suggest putting in your class folder as well.

Third File:  Test file - you can name it whatever you want.

Also - as far as simple... I made a staff_email.php file that allows staff to see (obviously, re-used my IP Banning code... LOL)

 

<?
session_start();
include "sglobals.php";

if($ir[user_level] != 2){
echo "You are not an administrator and should not be trying to access this file.

Logged.";
stafflog_add("<font color=\"red\">Attempted to access email ban (not admin)</font>");
$h->endpage();
exit;
}

if(!isset($_POST[submit])){
banform();
$h->endpage();
exit;
}
else
{
ban_ip();
$h->endpage();
exit;

}

function ban_ip(){
global $db, $ir, $h;

$reason = mysql_real_escape_string($_POST[ban_reason]);
$address = mysql_real_escape_string($_POST[address]);

$db->query("INSERT INTO blacklist_domains (bl_text, bl_reason, bl_date, bl_userid) VALUES ('$address', '$reason', unix_timestamp(), $ir[userid])");

echo "You have banned the domain:  $address for $reason.

This has been logged.";

stafflog_add("Banned domain: $address");
echo "<hr>";

banform();
$h->endpage();
exit;

}


function banform(){
global $db, $ir, $h;

$ipq = "SELECT * FROM blacklist_domains WHERE bl_text = '$_GET[address]'";
$ips = $db->query($ipq);

if($db->num_rows($ips) > 0){
	echo "<font color=\"red\">This email is already banned\"</font>
";

}

require("class/email_validation.php");

$validator=new email_validation_class;

if(!function_exists("GetMXRR"))
{
	$_NAMESERVERS=array();
	include("getmxrr.php");
}
$validator->timeout=10;
$validator->data_timeout=0;
$validator->localuser="mailtestacct";
$validator->localhost="alteredfuture.com";
$validator->debug=0;
$validator->html_debug=1;
$validator->exclude_address="";

if(IsSet($_GET["address"]))
	$email=$_GET["address"];
if(IsSet($email)
&& strcmp($email,""))
{
	if(($result=$validator->ValidateEmailBox($email))<0)
		echo "<font color=\"yellow\">It was not possible to determine if [b]$email[/b] is a valid address.</font>\n";
	else
		echo "<font color=\"yellow\">[b]$email[/b] is ".($result ? "" : "<font color=\"red\">not</font> ")."a valid address.</font>\n";
}
else
{
	$port=(strcmp($port=getenv("SERVER_PORT"),"") ? intval($port) : 80);
	$site="http://".(strcmp($site=getenv("SERVER_NAME"),"") ? $site : "localhost").($port==80 ? "" : ":".$port).GetEnv("REQUEST_URI");
	echo "<H2>Access this page using a URL like: $site?email=<A HREF=\"[email protected]\"><TT>[email protected]</TT></A></H2>\n";
}




list($username, $domain)=split('@',$_GET[address]); 

echo '
	<form action="staff_email.php" method="post">
	  <table width="500" border="0" cellspacing="0" cellpadding="0">
		<tr> 
		<td colspan="2"> </td>
	  </tr>
	  <tr> 
		  <td>Domain to blacklist:</td>
		<td><input name="address" type="text" size="30" maxlength="30" value="'.$domain.'"></td>
	  </tr>
	  <tr> 
		<td>Reason:</td>
		<td><input name="ban_reason" type="text" size="50" maxlength="50"></td>
	  </tr>
	  <tr>

		<td colspan="2"><div align="right">
			  <input type="submit" name="submit" value="Submit">
			</div></td>
	  </tr>
	</table>
	</form>
}

?>

 

When the administrator clicks on the users email address from the admin panel - they see one of the following:

valid-email.tiff

not-valid-email.tiff

Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...
  • 2 weeks later...

Re: Awesome 1st step to email validation.

its a nice modification some people may think it it really good but i think it isn't because 100 game users about 70 will have msn and the others that dont they will not be able to join which isnm't really fair and some dont like joining games that have email validation. :|

Link to comment
Share on other sites

  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...