0

如果登录成功,该代码应该在其 HTML 元素中回显特定内容

但是问题是……一旦我登录,它会显示一个页面,上面写着“该用户不存在或尚未激活,请按回”。当我按下浏览器上的“返回”按钮时,它会显示登录成功时应该生成的 HTML 元素。

“该用户不存在或尚未激活,请按回”应该仅在查询结果为空或至少不是 1 时显示。

这是供参考的代码:

<?php
include_once("check_login_status.php");
// Initialize any variables that the page might echo
$e = "";
$joindate = "";
$lastsession = "";

// Make sure the _GET email is set, and sanitize it
if(isset($_GET["em"])){
    $e = $_GET["em"];
    // echo $e;
} else {
    header("location: http://www.yoursite.com");
}
// Select the member from the users table
$sql = "SELECT * FROM user WHERE email='$e' AND active='1' LIMIT 1";
$user_query = mysqli_query($db_connect, $sql);
// Now make sure that user exists in the table
$numrows = mysqli_num_rows($user_query);
// echo $numrows;
if( $numrows != 1 ){
    echo "That user does not exist or is not yet activated, press back";
    exit(); 
}
// Check to see if the viewer is the account owner
$isOwner = "No";
if($e == $log_email && $user_ok == true){
    $isOwner = "Yes";
}
// Fetch the user row from the query above
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
    $profile_id = $row["id"];
    $signup = $row["signup"];
    $lastlogin = $row["lastlogin"];

    $joindate = strftime("%b %d, %Y", strtotime($signup));
    $lastsession = strftime("%b %d, %Y", strtotime($lastlogin));
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo $u; ?></title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="style.css">
<script src="main.js"></script>
<script src="ajax.js"></script>
</head>
<body>
<div id="pageMiddle">
  <h3><?php echo $e; ?></h3>
  <p>Is the viewer the page owner, logged in and verified? <b><?php echo $isOwner; ?></b></p>
  <p>Join Date: <?php echo $joindate; ?></p>
  <p>Last Session: <?php echo $lastsession; ?></p>
</div>
</body>
</html>

我已经做了一些回声测试,似乎在这个单独的测试中......

include_once("db_connect.php");
$e = "MY EMAIL";
$sql = "SELECT * FROM user WHERE email='$e' AND active='1' LIMIT 1";
$user_query = mysqli_query($db_connect, $sql);
// Now make sure that user exists in the table
$numrows = mysqli_num_rows($user_query);
echo $numrows;

numrows 回显 '1' - 而在主代码中,numrows 回显 ()...这很奇怪,因为当我通过 echo 检查时 $_GET["em"] 与 MY EMAIL 相同。

4

1 回答 1

-1

这很奇怪,因为......

不,它不是有线的,根本不存在问题!

我没有看到任何错误,所以错误在这个 PHP 中:

include_once("check_login_status.php");

或者你没有连接数据库

$user_query = mysqli_query($db_connect, $sql);

在 php.ini 中启用错误日志(参见http://php.net/manual/it/errorfunc.configuration.php):

log_errors = 开启

并检查 apache(或其他)Web 服务器日志中的错误。

或者尽量不要重新发明“热水”并使用已经完成的用户管理类:

哨兵@Cartalyst

于 2013-08-01T06:02:17.510 回答