0

当我单击提交按钮而不输入任何字段时,我的错误处理似乎不起作用,我仍然可以登录我到底错过了什么??看来我的验证不起作用,这是我在 login.php 下面的代码

<?php
include 'core/init.php';
    if (empty($_post) === false) {
    $username = $_post['username'];
    $password = $_post['password'];

    if (empty($username) === true  || empty($password) === true) {
      $errors[] = 'You need to enter a username and password';

    } else if (user_exists($username) === false ) {

      $errors[] = 'Username not found';

    } else if (user_active($username) === false ){

       $errors[] = 'You haven\' activated your account';

    } else {

        if (strlen($password) > 32){
          $errors[] = 'Password too long';

        }

        $login = login($username, $password);

        if($login === false){

         $errors[] = 'That username/password combination is incorrect';

        } else {

        $_session['user_id'] = $login;
        header('location: index.php');
        exit();

        }

    }
} else {

  $errors[] = 'No data recieved';
}

include 'includes/overall/header.php';
if (empty($errors) === false){
?>
<h2> we tried to log you in, but...</h2>
<?php
echo output_errors($errors);

}
include 'includes/overall/footer.php';

?>

我的 init.php

<?php
 session_start();
 require 'database/connect.php';
 require 'functions/general.php';
 require 'functions/users.php';
 $errors = array();
?>

通用.php

<?php
function sanitize($data){
return mysql_real_escape_string($data);
}
function output_errors($errors) {

 return '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>';
}
?>
4

1 回答 1

0

使用 $_POST 而不是 $_post,它们都是不同的变量,因为 php 对变量名区分大小写。

于 2013-03-23T17:21:38.533 回答