PHP登录系统问题

PHP登录系统问题,php,mysql,login,mysqli,Php,Mysql,Login,Mysqli,我正在为一家小企业开发一个PHP web应用程序,现在我正在尝试将登录系统合并到该应用程序中。我有一个login.php页面,它收集UN/PW并通过$\u POST存储,我的UN/PW存储在一个带有MD5散列的MySQL表中。当我从login.php单击login按钮时,它调用includes/login.inc.php并处理登录。但是,我只在调用login.inc.php时看到一个空白页面。我不确定我的问题在哪里 login.php: <!DOCTYPE html PUBLIC "-//

我正在为一家小企业开发一个PHP web应用程序,现在我正在尝试将登录系统合并到该应用程序中。我有一个login.php页面,它收集UN/PW并通过$\u POST存储,我的UN/PW存储在一个带有MD5散列的MySQL表中。当我从login.php单击login按钮时,它调用includes/login.inc.php并处理登录。但是,我只在调用login.inc.php时看到一个空白页面。我不确定我的问题在哪里

login.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <meta http-equiv="Content-type" content="text/html;charset=utf-8" />
  <title>Login Page</title>
  <link rel="stylesheet" type="text/css" href="css/login.css" />
</head>
<body>
  <form id="login-form" method="post" action="includes/login.inc.php">
    <fieldset>
      <legend>Login to Inventory System</legend>
      <p>Please enter your username and password to access the Inventory system</p>
      <label for="username">
        <input type="text" name="username" id="username" />Username:
      </label>
      <label for="password">
        <input type="password" name="password" id="password" />Password:
      </label>
      <label>
        <input type="submit" name="submit" id="submit" value="Login" />
      </label>
    </fieldset>
  </form>
</body>

</html>
login.inc.php:

<?php
// Include required MySQL configuration file and functions
require_once('config.inc.php');
require_once('functions.inc.php');

// Start session
session_start();

// Check if user is already logged in
if ($_SESSION['logged_in'] == true) {
    // If user is already logged in, redirect to main page
    redirect('../index.php');
  } else {
    // Make sure that user submitted a username/password and username only consists of alphanumeric chars
    if ( (!isset($_POST['username'])) || (!isset($_POST['password'])) OR
      (!ctype_alnum($_POST['username'])) ) {
        redirect('../login.php');
    }

// Connect to database
$mysqli = @new mysqli('localhost', 'username', 'password', 'db_name');

// Check connection
if (mysqli_connect_errno()) {
  printf("Unable to connect to database: %s", mysqli_connect_error());
    exit();
}

// Escape any unsafe characters before querying database
$username = $mysqli->real_escape_string($_POST['username']);
$password = $mysqli->real_escape_string($_POST['password']);

// Construct SQL statement for query & execute
$sql = "SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . md5($password) . "'";
$result = $mysqli->query($sql);

// If one row is returned, username and password are valid
if (is_object)($result) && $result->num_rows == 1) {
  // Set session variable for login status to true
  $_SESSION['logged_in'] = true;
  redirect('../index.php');
} else {
  // If number of rows returned is not one, redirect back to login screen
  redirect('../login.php');
  }
}
?>
有人看到我的问题了吗


谢谢

如果您有一个空白屏幕,您很可能会遇到致命错误。有关详细信息,请查看错误日志。或者把这个放在脚本的顶部

error_reporting(E_ALL);
ini_set('display_errors', '1');
我发现了你的一个问题

// This is a syntax error
if (is_object)($result) && $result->num_rows == 1) {

// Correct
if (is_object($result) && $result->num_rows == 1) {

没有对这个问题进行评论,MD5哈希是不安全的。您至少需要一个salt。停止限制用户名的字符集。停止使用STFU运算符抑制错误。停止对位置标头使用相对URI。停止存储未加密和未加密的密码。启用错误报告。开始使用绑定参数使用准备好的语句。@PeeHaa-salt密码计划与其他增强功能一起使用,例如转义所有mysql输入。我对PHP非常陌生,在学习的过程中会不断学习,所以我会在提高PHP的水平之前确保基本功能已经存在。该系统也尚未在现场运行,所有测试均在本地进行。我知道我没有正确地记录错误,所以你能告诉我如何正确地记录错误吗?还有,我怎么能不使用相对URI呢@佩哈,谢谢。一旦我弄明白为什么我当前的代码不起作用,我就会回去修复那些其他问题。我似乎无法获取用于login.inc.php的调试信息。谢谢。我已经修复了语法错误,现在我不再得到空白页。实际上,我似乎被一次又一次地重定向到login.php。这使得login.inc.php正常工作,但我的UN/PW不正确,或者无法访问数据库。忽略我的最后一条评论。我解决了这个问题。我仍然得到一个空白页面,并且我已经将调试信息添加到login.inc.php的顶部,但是没有得到调试信息。听起来像是另一个语法错误。尝试在脚本上运行php-l。