我需要放一个数字并重定向到另一个url php



你好,我不知道为什么当我提交一个数字时,我只得到第一部分,这是我的代码,我希望我能得到帮助我想当用户键入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;
}
?>```

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

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

工作示例

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===的用法示例

最新更新