Source for file login.class.php
Documentation is available at login.class.php
* A typical use of the validating mode is to use:
* if (checkEmail($email_address)) {
* print 'Your email address is not valid';
* A typical use of the debugging mode is to use:
* $return_msgs = checkEmail($email_address, true);
* foreach($return_msgs[1] as $debug_msg) { print htmlspecialchars($debug_msg).'<br />'; }
* print $return_msgs[0] ? 'Email address seems to be valid' : 'Email address does not seem to be valid';
* @param $email Email to be checked
* @param $blnDebug Debug mode enabled
* @return array(checked, valid, messages)
$msgs[] = 'Received email address: '. $email;
// Check for email pattern (adapted and improved from http://karmak.org/archive/2003/02/validemail.html)
//----------------------------------------------------------------------------------------------------
// incorrectly allows IP addresses with block numbers > 256, but those will fail to create sockets anyway
// unicode norwegian chars cannot be used: C caron, D stroke, ENG, N acute, S caron, T stroke, Z caron (PHP unicode limitation)
$msgs[] = 'Email address was not recognised as a valid email pattern';
return $blnDebug ? Array (true , false , $msgs) : false;
$msgs[] = 'Email address was recognised as a valid email pattern';
$mxHost[0 ] = preg_replace("/[\w\W]*@\[([\d.]+)\]$/", "$1", $email);
$msgs[] = 'Email address contained IP address '. $mxHost[0 ]. ' - no need for MX lookup';
// Get all mx servers - if no MX records, assume domain is MX (SMTP RFC)
$domain = preg_replace("/^[\w\W]*@([^@]*)$/i", "$1", $email);
if (!@getmxrr($domain, $mxHost, $weightings))
$msgs[] = 'Failed to obtain MX records, defaulting to '. $domain. ' as specified by SMTP protocol';
$cnt.= ($cnt ? ', ' : '') . $ch . ' (' . $weightings[$co] . ')';
$msgs[] = 'Obtained the following MX records for '. $domain. ': '. $cnt;
// Check each server until you are given permission to connect, then check only that one server
foreach ($mxHost as $currentHost)
$msgs[] = 'Checking MX server: '. $currentHost;
if ($connection = @fsockopen($currentHost, 25 ))
$msgs[] = 'Created socket ('. $connection. ') to '. $currentHost;
$msgs[] = $currentHost. ' sent SMTP connection header - no futher MX servers will be checked: '. $cn;
$cn = @fgets($connection, 1024 );
$msgs[] = $currentHost. ' sent extra connection header: '. $cn;
} //throw away any extra rubbish
// Attempt to send an email from the user to themselves (not <> as some misconfigured servers reject it)
@fputs($connection, 'HELO '. ($localHostName ? $localHostName : ('['. $localHostIP. ']')). "\r\n");
$hl = @fgets($connection, 1024 );
$msgs[] = $currentHost. ' sent HELO response: '. $hl;
@fputs($connection, " MAIL FROM: <$email>\r\n" );
$from = @fgets($connection, 1024 );
$msgs[] = $currentHost. ' sent MAIL FROM response: '. $from;
@fputs($connection, " RCPT TO: <$email>\r\n" );
$to = @fgets($connection, 1024 );
$msgs[] = $currentHost. ' sent RCPT TO response: '. $to;
$msgs[] = $currentHost. ' rejected recipient: '. $to;
$msgs[] = $currentHost. ' rejected MAIL FROM: '. $from;
$msgs[] = $currentHost. ' rejected HELO: '. $hl;
@fputs($connection, "QUIT\r\n");
@fgets($connection, 1024 );
// See if the transaction was permitted (i.e. does that email address exist)
$blnReturn = ($success == '1') ? true : false;
$msgs[] = $blnReturn ? ('Email address was accepted by '. $currentHost) : ('Email address was rejected by '. $currentHost);
return $blnDebug ? Array (true , $blnReturn, $msgs) : $blnReturn;
$msgs[] = 'Mail domain denies connections from this host - no futher MX servers will be checked: '. $cn;
return $blnDebug ? Array (false , true , $msgs) : false;
$msgs[] = $currentHost. ' did not send SMTP connection header: '. $cn;
$msgs[] = 'Failed to create socket to '. $currentHost;
$msgs[] = 'Could not establish SMTP session with any MX servers';
return $blnDebug ? Array (false , true , $msgs) : false;
define('ERR_USERNAME_EMPTY', 'You forgot to enter a username, please try again');
define('ERR_USERNAME_INVALID', 'The username you entered is invalid. Please try "peter" (without quotes)');
define('ERR_PASSWORD_EMPTY', 'You forgot to enter a password, please try again');
define('ERR_PASSWORD_INVALID', 'The password you entered is invalid. Please try "gabriel" (without quotes)');
define('ERR_EMAIL_EMPTY', 'You forgot to enter an e-mail address');
define('ERR_EMAIL_INVALID', 'The e-mail address you entered is invalid. Please enter a valid e-mail address.');
* Login class used in the "login form" example
* Please note: Constructors and private methods marked with _ are never exported in proxies to JavaScript
* @author Gilles van den Hoven <gilles@webunity.nl>
* @copyright 2005 Gilles van den Hoven
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version Release: @package_version@
* @link http://pear.php.net/package/HTML_AJAX
function _checkEmail ($strEmail) {
* Checks if the passed values are correct.
* An array will be returned consisting of the following items:
* 1) the result of this function
* 2) the id's of the failing items
* 3) the (error) messages
* @param string the username to be checked
* @param string the password to be checked
* @param string the email addres from the user
function checklogin($strUsername, $strPassword, $strEmail) {
// Initialize return values
$arrResult = array (false , array (), array ());
// Don't trust passed values :)
$strUsername = trim($strUsername);
$strPassword = trim($strPassword);
$strEmail = trim($strEmail);
if ($strUsername == '') {
$arrResult[2 ][] = 'username';
} else if ($strUsername != 'peter') {
$arrResult[2 ][] = 'username';
if ($strPassword == '') {
$arrResult[2 ][] = 'password';
} else if ($strPassword != 'gabriel') {
$arrResult[2 ][] = 'password';
$arrResult[2 ][] = 'email';
$arrResult[2 ][] = 'email';
// (to avoid we are adding thesame "error message" or "id" twice, we use the array_unique() function.)
$arrResult[0 ] = (count($arrResult[1 ]) == 0 );
Documentation generated on Mon, 11 Mar 2019 14:11:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|