What are the implications of allowing users to register without email confirmation in terms of security and user verification?

Allowing users to register without email confirmation can lead to potential security risks such as fake accounts, unauthorized access, and spam registrations. To ensure proper user verification and security, it is essential to implement email confirmation during the registration process.

// Check if email is valid and not already registered
if(filter_var($email, FILTER_VALIDATE_EMAIL) && !emailExists($email)){
    // Generate a unique verification code
    $verification_code = generateVerificationCode();

    // Save the verification code and user details to the database
    saveUserDetails($email, $password, $verification_code);

    // Send an email with the verification code to the user
    sendVerificationEmail($email, $verification_code);

    // Redirect user to a verification page
    header('Location: verification.php');
    exit();
}else{
    // Handle invalid email or existing email address
}