我正在尝试创建一个没有注册的登录页面。我尝试了很多不同的方法,但我得到的只是一个空白页。我的用户表如下
id username password group
x xx xx xx
这是我的登录操作文件:
<?php
if ($_SERVER['REQUEST_METHOD'] =='POST')
{
require ('php_includes/dbc_connect.php');
require ('login_tools.php');
list ($check, $data) =
validate ($dbc, $_POST['username'], $_POST['password']);
if($check)
{
session_start();
$_SESSION['id'] = $data['id'];
$_SESSION['username'] = $data['username'];
$_SESSION['password'] = $data['password'];
load('Stafflogin.php');
}
else{ $errors = $data;}
mysqli_close($dbc);
include ('index31.php');
}
?>
<?php
function load ($page = 'index31.php')
{
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
$url = rtrim( $url,'/\\');
$url .= '/' .$page;
header("Location: $url");
exit();
}
function validate($dbc ,$username = '' ,$password = '')
{
$errors = array();
if(empty($username))
{$errors[] = 'Enter your username.';}
else
{ $n = mysqli_real_escape_string($dbc, trim($username));}
if(empty($password))
{$errors[] = 'Enter your password.';}
else
{$p = mysqli_real_escape_string($dbc, trim($password));}
if (empty($errors))
{
$q = " SELECT id, username, password FROM USERS WHERE username = '$n'
AND PASSWORD = SHA1('$p')";
$r = mysqli_query($dbc, $q);
if(mysqli_num_rows( $r ) == 1)
{
$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
return array(true,$row);
}
else
{$errors[] = 'Username and password not found.';}
}
return array(false,$errors);
}
?> this is logintools.php
并且登录表单在页面顶部包含以下代码
if(isset($errors)&& !empty($errors))
{
'<p id="err_msg">Oops!There was a problem:<br>';
foreach($errors as $msg)
{
echo"- $msg<br>";
}
echo"Please try again<br></p>";
}
你能告诉别人我错在哪里吗?
答案 0 :(得分:0)
首先,将以下代码放在所有这些脚本之上,以确切了解发生了什么:
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
然后你会看到你的应用程序在哪里破解。