Monday 8 September 2014

Username auto generation using php

login username automatic generation. while  registration time user registering their username in the username column, that time the same user name already exist in the database, for that we are creating auto generation of  username like gmail and all. like that we are suggesting some username for users.

DOWNLOAD                 LIVE DEMO


HTML

html form for username auto generation.
<form  method="POST">
    <label>Email</label>
      <input type="text" name="email" id="email" />
    <label>Generate username</label>
      <input type="text" name="loginname" readonly id="loginname" />
</form>


Script

Ajax script for username auto generation.
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
 $(document).on('change','#email',function(){
        var url = "check.php"; 
            $.ajax({
              type: "POST",
              url : url,
              data: $("#email").serialize(),
              success: function(data)
               {
                 $('#loginname').val(data);  
               }
           });          
        return false;
    });
</script>


Check.php

to generate automatic username.
<?php
if($_POST['email']!='')
        {
            extract($_POST);
            $checkemail =$email;            
            $user = preg_replace('/([^@]*).*/', '$1', $checkemail);         
            echo $uuser = $user.rand ( 1 , 99 );
        }
?>

6 comments:

  1. It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time.
    Computer Repair Lakewood Ranch

    ReplyDelete
  2. The place else may just I get that kind of information written in such an ideal means? I have a venture that I’m just now operating on, and I have been on the look out for such information.
    IPad radiation case at Amazon

    ReplyDelete
  3. Nice tutorial very helpful there is another tutorial on TalkersCode.com to suggest username and emailid on user signup using jquery,ajax and php http://talkerscode.com/webtricks/auto-suggestion-of-username-and-email-id-on-user-registation-using-ajax-jquery-and-php.php you must have to look at that its very easy and helpful

    ReplyDelete
  4. I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot! ICT Web Design

    ReplyDelete

© All rights reserved @ 1next2.com