值肯定是POSTED但isset()表示NO

时间:2021-05-11 13:26:05

See the code give given below. I was fighting with this code since last 5 hours to know why isset() is evaluating the condition as false if value is posted exactly what it shall POST. If I uncomment the line no. - 4,5,6,7,8 and put rest of the code from line no. 10 to 28 I can see the POSTED value . Can Anyone help in this by any guidance or suggestion. I will be thankful.

请参阅下面给出的代码。自从过去5个小时以来我一直在与这段代码作斗争,以了解为什么isset()正在将条件评估为false,如果值的确是张贴它的POST。如果我取消注释行号。 - 4,5,6,7,8并将其余代码放在第5行。 10到28我可以看到POSTED值。任何人都可以通过任何指导或建议为此提供帮助。我会感恩的。

<?php
include 'dbconnection.php';
include 'functions.php';

// var_dump($_POST); what happens when you uncomment this line?

//sec_session_start();
 //  $email = $_POST['logemail'];
 //  $password = $_POST['p'];
//  echo $password;
//  echo $email;
 // Our custom secure way of starting a php session. 

if(isset($_POST['logemail'], $_POST['p'])) { 
   $email = $_POST['logemail'];
   $password = $_POST['p']; // The hashed password.
   if(login($email, $password, $mysqli) === true) {
      // Login success
      //$url = 'mwq';
    //echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';  
    echo $password;
    echo $email;

   } else {
      // Login failed
      header('Location: login.php?error=1');
   }
} else { 
   // The correct POST variables were not sent to this page.
   echo 'Invalid Request Data Not POSTED';
}
?>

1 个解决方案

#1


0  

Without seeing the form I can only theorize what happens:

没有看到形式,我只能理解发生的事情:

  1. You started with a clean slate, the form shows, you enter the username and password and submit it
  2. 您从一个干净的平板开始,表单显示,您输入用户名和密码并提交
  3. The code passes the condition and then performs the login
  4. 代码传递条件然后执行登录
  5. The result of login(...) !== true for whatever reason (wrong password or bug in the code)
  6. 登录(...)的结果!==无论出于何种原因都是真的(密码错误或代码中的错误)
  7. The page redirects to login.php?error=1.
  8. 该页面重定向到login.php?error = 1。

Now, the $_POST is empty and $_REQUEST contains array('error' => 1). Perhaps the login.php shouldn't redirect to itself but rather redirect back to the page where you show the form.

现在,$ _POST为空,$ _REQUEST包含数组('error'=> 1)。也许login.php不应该重定向到自己,而是重定向回到您显示表单的页面。

#1


0  

Without seeing the form I can only theorize what happens:

没有看到形式,我只能理解发生的事情:

  1. You started with a clean slate, the form shows, you enter the username and password and submit it
  2. 您从一个干净的平板开始,表单显示,您输入用户名和密码并提交
  3. The code passes the condition and then performs the login
  4. 代码传递条件然后执行登录
  5. The result of login(...) !== true for whatever reason (wrong password or bug in the code)
  6. 登录(...)的结果!==无论出于何种原因都是真的(密码错误或代码中的错误)
  7. The page redirects to login.php?error=1.
  8. 该页面重定向到login.php?error = 1。

Now, the $_POST is empty and $_REQUEST contains array('error' => 1). Perhaps the login.php shouldn't redirect to itself but rather redirect back to the page where you show the form.

现在,$ _POST为空,$ _REQUEST包含数组('error'=> 1)。也许login.php不应该重定向到自己,而是重定向回到您显示表单的页面。