Ad Space
Ad Space

Hosting Geared For
your CMSMS needs

CMSMS ready Hosting

Hosting Starting at $15

  • • Hosted Mail
  • • Personal Control Panel
  • • CMSMS 1.8.1 tested
  • • Lightly packed servers
  • • Intrusion Detection
  • • URL monitored
  • • Custom solutions available

Order your hosting Now

CP Blogs

check email/username for FEU

Posted by: Jeremy Bass
on Jan 17, 2010

Category:

Coding, Intermediate, Smarty, HTML, jQuery, CMS Made Simple

Modules Used

Frontend User Management

Summary:

Sometimes, when building a user based site, we need to check if a usename is already created. Using the auto generated usernames for FEU sort of solves this but will not protect from a user just makeing tons of accounts. So I lick to take it to the next level. Here is a simple way to check of full unquness.


Ad Space

Sometimes, when building a user based site, we need to check if a username is already created. Using the auto generated usernames for FEU sort of solves this but will not protect from a user just making tons of accounts. So I lick to take it to the next level. Here is a simple way to check of full uniqueness.

In this example $_GET['cntnt01fbrp__39'] is an ajax call from formbuilder... You would/could change the get to email or something. This also suggest some valid alternates... ie: if you are not using an email for the user name then you would want to give the alternates...

So this uses checkdnsrr to realy keep down the spam and false leads down to a min. checkdnsrr() checks DNS records corresponding to a given Internet host name or IP address.

 global $gCms; $FEU = $gCms->modules['FrontEndUsers']['object']; // A FUNCTION TO TEST FOR A VALID EMAIL ADDRESS, RETURN TRUE OR FALSE function check_valid_email($email){ // IS THE PATTERN OF THE EMAIL ADDRESS OK? if (!preg_match('/^[A-Z0-9_-][A-Z0-9._-]*@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,6}$/i', $email)) return FALSE; // IS THE DOMAIN OF THE EMAIL ADDRESS ROUTABLE OVER THE INTERNET FOR MX OR A RECORDS? $emaila = explode('@', $email); if ( checkdnsrr($emaila[1],"MX") || checkdnsrr($emaila[1],"A") ) return TRUE; // NOT ROUTABLE return FALSE; } if (!empty($_GET['cntnt01fbrp__39'])){ $e = $_GET['cntnt01fbrp__39']; if (check_valid_email($e)){ echo "<br/>VALID: $e \n"; if($FEU->GetUserID($e)){ $e1=$e; while ($FEU->GetUserID($e1)) { $e1=$e.rand(5, 100); } $e2=$e.rand(5, 100); while ($FEU->GetUserID($e2)) { $e2=$e.rand(5, 100); } echo '<span style="color:red">This is not available</span> <span style="color:green">'.$e1.' and '.$e2.' is available</span>'; return 'false'; }else{ echo "<br/>AVAILABLE: $e \n"; return 'true'; } }else{ echo "<br/>BOGUS: $e \n"; return 'false'; } } 

Hope this helps
Cheers

jeremyBass

Ad Space

Get Social With It

[+]

Add A Comment

[+]

Code in the picture:
Title:
Your Name(*):
Email:
Notify me of any further comments to this thread:
Website:
Comment(*):
 
Previous page: Hosting FAQ Next page: Experimental