PHP $ _GET对我不起作用

时间:2013-02-26 01:37:44

标签: php

我的代码如下:

<?php 
require 'database/db.php';
if($_SERVER["REQUEST_METHOD"] == "POST") {
   $name = $_POST["userid"];
   $password = $_POST["password"];
   if (empty($name) || empty($password)) {
      header("Location : AdminLogin.php?status=failure");
       exit();
    }
   $count = verifyUser($name, $password);
    if($count == 1 )
     {
        header("Location : AdminLogin.php?status=success");
      }
    else {
        header("Location : AdminLogin.php?status=failure");
      }

   exit;
}
?>
<?php include('inc/header.php'); ?>
  <div class = "section page">
    <div class ="wrapper">
      <div class="page-header">
        <b>Admin Login </b>
      </div>
      <?php if(isset($_GET["status"]) AND $_GET["status"]=="success") { ?>
        <p> Your login was a success .. I will redirect you to another page.</p>
      <?php } else {?>
      <form method="post" class="form-signin" action="AdminLogin.php">
        <h2 class="form-signin-heading">Sign In</h2>
        <input type="text" name ="userid" class="input-block-level" placeholder="UserID...">
        <input type="password" name ="password" class="input-block-level" placeholder="Password...">
        <button class="btn btn-large btn-primary" type="submit">Sign in</button>
      </form>
        <?php } ?>
    </div>
  </div>

<?php include('inc/footer.php'); ?>

当我单击“登录”按钮时,我会在服务器端执行用户验证并返回一个int(应该是bool,我同意)登录是否成功。

我正在重定向到同一页面。

调查结果......

我已经确认$ count正在正确退回。即如果用户名和密码匹配count = 1,则count!= 1。到现在为止还挺好。我也注意到它在那之后失败了。

由于 GAGAN

编辑:verifyUser(这只是一个存根)

function verifyUser($username, $password)
{
    return  strcmp ( $username , $password )
}

2 个答案:

答案 0 :(得分:1)

尝试删除Location之后的额外空格:

... header("Location : ...
                    ^

答案 1 :(得分:0)

你没有显示verifyUser(),是否会返回“truthy”?因为您正在测试它是否为true / boolean。