Currently my email accepts all email domains. I would like to define which ones are allowed out of a list (solent.ac.uk, herts.ac.uk) rather than public ones such as @gmail.com etc. Whichever way is easiest for now, i'll try alternative ways for now, this is more just temporary. I am just editing a script I bought and wanted this small change. I know it must require more than just the code I produced below to be edited but thought i'd start with something. This is part of my registration.php page: <form method="post" action="<?php url_for('register'); ?>">[/SIZE] [SIZE=3] <!--Email-->[/SIZE] [SIZE=3] <p class="email field">[/SIZE] [SIZE=3] <input tabindex="1" id="email" type="text" name="email" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" placeholder="email@example.com" autofocus />[/SIZE] [SIZE=3] <a href="<?php url_for('login'); ?>" tabindex="2" class="action button register" title="Click to log-in with your existing account.">Login</a>[/SIZE] [SIZE=3] </p>[/SIZE] [SIZE=3] HTML:
in your url_for('login'); use if(strpos(@solent.ac.uk, $_POST['email']) { // Continue email script }else{ echo 'Sorry, you can't register with that email address!'; } Code (markup):
I ended up using this: $whitelist = array('solent.ac.uk', 'herts.ac.uk'); list(, $domain) = array_pad(explode('@', $email, 2), 2, ''); if (!in_array($domain, $whitelist)) { $app->flashNow('error', __('login_invalidemail')); PHP: Is it possible to require just the .ac.uk part instead of example.ac.uk. I want to allow all university emails only but obviously it would take hours finding every single university name and its extension (). Would be quicker to just define/restrict to: .ac.uk .edu and so on...
That can be a bit tricky in knowing what to do with subdomains. For instance, the following code produces the following output: <?php var_dump(getDomainExtension('example.an.cd')); var_dump(getDomainExtension('subdomain.example.an.cd')); function getDomainExtension($domain) { return implode('.', array_splice(explode('.', $domain), 1)); } PHP: string(5) "an.cd" string(13) "example.an.cd" Code (markup):