0

I am trying to create a form that confirms the user has entered one of the allowed email addresses then redirects the user to the page "NewPost.php"; otherwise (if the user has not entered one of the allowed email addresses), they are stuck on this page. Currently, I can get the entree passed to the next page if I change

<form action="Verify.php">

to

<form action="NewPost.php"> 

but this disregards the conditional. The form is as follows:

<form action="Verify.php" method="post" name="VerifyEmail" id="VerifyEmail">
<p>Please enter your student email address</p>
<p> <input type="text" name="Email" size="40" maxlength="40" required/></p>
<p><input type="submit" name="Post" value="Post"/></p>
</form>

And the PHP; the $allowed variable is the array of schools whose .edu email addresses should meet the conditional to allow the user entering their email address redirect to NewPost.php

<?php
$Email = trim($_POST['Email']);
$allowed = array ('columbia.edu', 'nyu.edu', 'fitnyc.edu', 'pratt.edu', 'newschool.edu', 'stjohns.edu', 'cooper.edu', 'manhattan.edu', 'pace.edu', 'bard.edu', 'berkeleycollege.edu', 'qc.cuny.edu');
$split = explode($Email, "@");
    $name = $split['0'];
    $school = $split['1'];
if ($school == $allowed) {
header('Location: /NewPost.php');
}
else{echo "<p>Sorry your school is not supported yet</p>";}
?>

To clarify, I want the visit entering their email address to be redirected to NewPost.php only if their email address is within the $allowed array, otherwise they're stuck on the current page (Verify.php). If anyone wants to try it themselves, the address is here

Thanks!

0

1 Answer 1

1

You're comparing a string to an array. You can't do that. You need to look to see if that string is in the array. Use either in_array() or isset():

if (in_array($school, $allowed)) {

or

if (isset($allowed[$school])) {
Sign up to request clarification or add additional context in comments.

3 Comments

Make sure the values in those variables are what you're expecting. A leading or trailing white space characters will throw things off. Also get rid of the quotes around your array keys: $name = $split[0]; $school = $split[1];
The TRIM should take care of the white space? Unfortunately it's still not working properly.
You have another error. You are calling explode with the parameters backwards. $split = explode("@",$Email);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.