php - Regarding unique username
My answer is going to address the specific problem you had regarding:
I need a solution from which i generate a unique username with available details also can check that a every student enters in database only one time and have only one username.
Because you stated that you have "first name", "last name" and "birthday" (which might be null) for each student, and need to create a unique username, I'm going to suggest using a checksum.
The real problem is that the data you have cannot in itself guarantee uniqueness, so even the solution I will suggest is not going to work 100% without you implementing some sort of random salt in the user data.
Here is a code snippet to help you see what I'm thinking:
$fname = "John"; $lname = "Doe"; $bday = "1980-03-01"; $unique_user_string = strtolower($fname . $lname . $bday); // not actually unique if 2 people have same name and birthday $username = ucfirst(substr($fname, 0, 1)) . ucfirst($lname) . crc32($unique_user_string);
From the above code, you should have a username like: JDoe4246458655
And the nice part is that you can always confirm an existing user by checking the checksum and creating a new one using the user data from your CSV. To get the checksum from the existing username, just do:
$crc = substr($username, -10, 10);
I hope this makes sense.