What are the best practices for user recognition in PHP to prevent multiple usernames?

To prevent multiple usernames in PHP, you can implement user recognition by checking if a username already exists in the database before allowing a new user to register. This can be done by querying the database to see if the username already exists, and if it does, displaying an error message to the user.

// Check if username already exists in the database
$username = $_POST['username'];
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysqli_query($conn, $query);

if(mysqli_num_rows($result) > 0) {
    echo "Username already exists. Please choose a different username.";
} else {
    // Proceed with user registration
}