How can PHP be used to restrict registration to specific email providers?

To restrict registration to specific email providers in PHP, you can use a combination of string manipulation functions and conditional statements to check if the email address entered by the user belongs to the allowed domain. By extracting the domain from the email address and comparing it against a list of allowed domains, you can prevent users from registering with email addresses from disallowed providers.

$email = $_POST['email'];
$allowed_domains = ['gmail.com', 'yahoo.com', 'hotmail.com'];

$email_domain = substr(strrchr($email, "@"), 1);

if (!in_array($email_domain, $allowed_domains)) {
    // Email domain is not allowed, display an error message
    echo "Sorry, registration with this email provider is not allowed.";
} else {
    // Email domain is allowed, proceed with registration
    // Additional registration logic here
}