How can a whitelist of email addresses be effectively stored and checked in PHP for registration purposes?

To effectively store and check a whitelist of email addresses in PHP for registration purposes, you can store the allowed email addresses in an array or database table. When a user attempts to register, you can check if their email address is in the whitelist before allowing them to proceed with the registration process.

// Array of whitelisted email addresses
$whitelist = ['example1@example.com', 'example2@example.com', 'example3@example.com'];

// Check if the user's email is in the whitelist
$user_email = $_POST['email']; // Assuming email is submitted via POST
if (in_array($user_email, $whitelist)) {
    // Proceed with registration
    echo "Email address is whitelisted. Registration successful.";
} else {
    // Display error message
    echo "Email address is not whitelisted. Registration failed.";
}