【问题标题】:i need to put a number and redirect to another url php [duplicate]我需要输入一个数字并重定向到另一个 url php [重复]
【发布时间】:2021-02-05 12:24:06
【问题描述】:

你好我不知道为什么当我提交一个数字时我只得到第一部分这是我的代码我希望我能得到帮助 我希望当用户类型 1 时他重定向到一个 url,当用户类型 2 时他重定向到另一个 url

<html>
<head>
 <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
 <meta charset="UTF-8">
</head>
<body>
<div class=top>
 <h2>6Virus | [ R00t ]</h2>
</div>
 <center>
 <img src="../img/anon.gif">
 <h2 style="font-size: 12px;">~# Catch Your Windows C:/ ~</h2>
 <img src="../img/app-store-2-128.png" style="margin-top: 10px;">
 <form name="form1" action="app.php" method="post">
     <input class=in type="text" name="here" placeholder="Here"/><br />
     <button class=sub type="submit" name="submit">Submit</button>
 </form>
</center>
</body>
</html>
<?php

if (isset($_POST['here']) == "1") {
 header("Location: https://instagram.com");
 exit;
}
elseif (isset($_POST['here'])  == "2") {
 header("Location: https://twitter.com");
 exit;
}
elseif (isset($_POST['here'])  == "3") {
 header("Location: https://google.com");
 exit;
}
?>```

【问题讨论】:

    标签: php html css web


    【解决方案1】:

    不要同时使用isset==,因为isset 返回一个布尔值,而== 1 是真值。

    相反,拆分您的逻辑以检查 isset 是否为 === 比较。

    工作示例

    if (isset($_POST['here']) && $_POST['here'] === "1") {
     header("Location: https://instagram.com");
     exit;
    }
    elseif (isset($_POST['here']) && $_POST['here'] === "2") {
     header("Location: https://twitter.com");
     exit;
    }
    elseif (isset($_POST['here']) && $_POST['here'] === "3") {
     header("Location: https://google.com");
     exit;
    }
    

    更好的方法

    如果您想要更简洁的方法,请事先检查 here 是否存在。

    if(isset($_POST['here'])) {
      if ($_POST['here'] === "1") {
        header("Location: https://instagram.com");
        exit;
      }
      elseif ($_POST['here'] === "2") {
        header("Location: https://twitter.com");
        exit;
      }
      elseif ($_POST['here'] === "3") {
        header("Location: https://google.com");
        exit;
      }
    }
    

    isset=== here 的示例用法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多