Gagan
Gagan

Reputation: 5656

PHP $_GET is not working for me

I have a code like as follows :

<?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'); ?>

As soon as I click the Sign In button , I perform validation of the user on the server side and return an int (should be bool, I agree) whether the login was successful or not.

I am redirecting to the same page .

Findings ...

I have verified that $count is being returned properly. i.e if the username and the password matches count = 1 else count !=1 . so far so good. I have also noticed that it fails after that.

Thanks Gagan

Edit : verifyUser (This is just a stub )

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

Upvotes: 0

Views: 106

Answers (2)

sprise
sprise

Reputation: 421

You didn't show verifyUser(), is it returning "truthy" perchance? Because you are testing whether or not it is true/boolean.

Upvotes: 0

Kermit
Kermit

Reputation: 34063

Try removing the extra space after Location:

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

Upvotes: 1

Related Questions