重定向如果有多个条件

时间:2014-01-01 11:08:53

标签: php url-redirection

PHP代码:

<?php
$referrer = $_SERVER['HTTP_REFERER'];
if (strpos($referrer, "bonaca.net46.net") === FALSE
    || !($_POST['pass'] == 1405 || $_POST['pass'] == 999)
{
    header('Location: index.php');
};
?>

我需要什么:

如果用户来自bonaca...之外的其他页面,或者他输入错误的通行证(正确的通行证是1405或999),则应重定向。

我得到了什么:

Parse error: syntax error, unexpected '{' in... on line 5

5 个答案:

答案 0 :(得分:1)

您缺少if语句的括号.. here

1405 || $_POST['pass'] == 999))
                              ^ //<---- Add like this

并且这里不需要分号

  header('Location: index.php');
}; //<---- Remove that

答案 1 :(得分:1)

您的一个条件是在if语句之外,请尝试:

if ((strpos($referrer, "bonaca.net46.net") === FALSE
    || !($_POST['pass'] == 1405 || $_POST['pass'] == 999))

答案 2 :(得分:1)

如果条件为),则会错过。请尝试使用此代码。

$referrer = $_SERVER['HTTP_REFERER'];
if (strpos($referrer, "bonaca.net46.net") === FALSE
    || !($_POST['pass'] == 1405 || $_POST['pass'] == 999))
{
    header('Location: index.php');
}

答案 3 :(得分:1)

Use this code

<?php
  $referrer = $_SERVER['HTTP_REFERER'];
      if (strpos($referrer, "bonaca.net46.net") === FALSE
          || !($_POST['pass'] == 1405 || $_POST['pass'] == 999)){
        header('Location: index.php');
     }

&GT;

答案 4 :(得分:1)

<?php

   $referrer = $_SERVER['HTTP_REFERER'];
    if (strpos($referrer, "bonaca.net46.net") === FALSE
        || !($_POST['pass'] == 1405 || $_POST['pass'] == 999))
    {
        header('Location: index.php');
    }
?>

试试这个。