donglei2288 2014-10-30 17:46
浏览 16

创建条件重定向PHP表单

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!

  • 写回答

1条回答 默认 最新

  • dongxing1960 2014-10-30 17:48
    关注

    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])) {
    
    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False