如果elseif else preg_match Windows位置



我正在创建一个表单,我希望有人回答是一个像2或7这样的数字,将被定向到不同页面。

我在网上搜索并开始做这个。

<?php
// define variables
$name "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
 if (!preg_match("/^3/",$name)) {
      echo "<meta http-equiv="refresh" content="0; URL=http://google.nl/">";
 } elseif (!preg_match("/^9/",$name)) {
      echo "<meta http-equiv="refresh" content="0; URL=http://osm.nl/">";
 }
   else {
      echo "<meta http-equiv="refresh" content="0; URL=http://facebook.nl/">";
}
}
?>

首先,我通过创建验证表格对其进行了测试,该表格正常。槽研究我编辑了代码。但是现在,当我尝试打开页面时,它是空白的。

我如何修复它可以重定向输入

我个人会使用switch语句和php标头函数重定向

在文件中,您将表格发布到:

$page = $_POST['name'];
switch($page)
{
    case 2:
        header("Location: http://www.google.com");
        break;
    case 7:
        header("Location: http://www.facebook.com");
        break;
}

应该做技巧。

,以下是您的所有错误:
第3行:$name "":在哪里" ="?
第7、9、12行:echo "<meta http-equiv="refresh":如果您还没有想到自己,请考虑使用标题为@nathanleadill说。

最新更新