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();
?>

general.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 に答える