How can PHP be used to prevent certain usernames from being used, including variations with different capitalization?

To prevent certain usernames from being used, including variations with different capitalization, you can convert all usernames to lowercase before checking if they are already in use. This way, usernames will be treated as case-insensitive and variations with different capitalization will be blocked.

// Convert the input username to lowercase
$username = strtolower($_POST['username']);

// Check if the lowercase username is already in use
if (in_array($username, $existingUsernames)) {
    echo "Username is already in use.";
} else {
    // Username is available, proceed with registration
}