我对 php 和 mysql 很陌生。我找到了一个很棒的教程来创建网站上的注册和登录部分。我正在设法很好地解构它并进行细微的更改。然而...
登录时,如果密码不正确,它会验证并返回错误。如果正确,它会登录。
我遇到的问题是,如果您输入了正确的密码,但在它既不验证也不登录后添加了额外的字符。只是进入一个空白页面。这是登录页面的验证码 -
<?php
include('db.php');
if(!isset($_POST['login']))//checking if user has entered this page directly
{
include('form.php');
}
else{
if(isset($_POST['user'])&&$_POST['user']==""||!isset($_POST['user']))
{
$error[] = "Username Field can't be left blank";
$usererror = "1";
}
if(!isset($usererror))
{
$user = mysql_real_escape_string($_POST['user']);
$sql = "SELECT * FROM users WHERE user = '$user'";
if(mysql_num_rows(mysql_query($sql))=="0")//1 means there is one entry same so we print error
{
$error[] = "Can't find a user with this username";
}
}
if(isset($_POST['pass'])&&$_POST['pass']==""||!isset($_POST['pass']))
{
$error[] = "password Field can't be left blank";
}
if(isset($error)){
if(is_array($error)){echo "<div class=\"error\"><span>please check the errors and refill the form<span><br/>";
foreach ($error as $ers) {
echo "<span>".$ers."</span><br/>";
}
echo "</div>";
include('form.php');
}
}
if(!isset($error)){
$suser=mysql_real_escape_string($_POST['user']);
$spass=md5($_POST['pass']);//for secure passwords
$find = "SELECT * FROM users WHERE user = '$suser' AND password = '$spass'";
if(mysql_num_rows(mysql_query($find))=="1"or die(mysql_error())){
session_start();
$_SESSION['username'] = $suser;
header("Location: loggedin.php");
}
else{
echo "<div class=\"warning\"><span>Some Error occured durring processing your data</div>";
}
}
}
?>
任何帮助将不胜感激...
编辑
我刚刚注意到我得到的唯一错误是如果没有输入密码。如果输入了错误的密码,我会看到空白页。谁能帮忙解释为什么密码没有被验证?