私は自分の知識を向上させるために単純なログインシステムに取り組んでいます。ユーザーが間違ったパスワードやユーザー名を入力したり、フィールドを入力しなかったり、何かを始めたときに警告メッセージを表示する方法を知っています私はそれが正しい方法であるかどうかわからないし、ログインフォームでページにメッセージを表示する方法がわからない。あなたの助けに感謝:)PHPログインエラーを表示するには?
は、これはこれはこれは私のfunction.phpあるログインフォームと私のインデックスファイル
<form class="form-signin" action="includes/ctrl_login.php" method="post">
<h3 class="form-signin-heading">Login </h3>
<div class="form-group">
<label for="username" class="sr-only">Username </label>
<input type="text" id="username" name="username" class="form-control" placeholder="Username">
</div>
<div class="form-group">
<label for="password" class="sr-only">Password</label>
<input type="password" id="password" name="userpassword" class="form-control" placeholder="Password">
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">login</button>
</form>
である私のログインコントローラ
<?php
/**
* Nome File : ctrl_login.php
* Descrizione: File che gestisce i dati inseriti nella pagina di login
*/
include('../config/konasi.php');
include('functions.php');
$user_name = check_input($_POST['username']);
$user_password = check_input($_POST['userpassword']);
if (!$user_name || !$user_password) {
echo "Non hai inserito username o password";
exit();
}
if ($stmt = mysqli_prepare($conn, "SELECT user_password FROM users WHERE user_name= ? ")) {
/* Bind parameters: s - string, b - blob, i - int, etc */
$stmt -> bind_param("s", $user_name);
/* Execute it */
$stmt -> execute();
/* Bind results */
$stmt -> bind_result($result);
/* Fetch the value */
$stmt -> fetch();
/* Close statement */
$stmt -> close();
}
if(password_verify($user_password, $result)) {
echo "you are connected!";
} else {
echo "Ops, wrong password";
}
mysqli_close($conn);
です
function check_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
あなたは多くの可能性があります。 'ctrl_login.php'では、ユーザをフォームのログインにリダイレクトし、クエリー文字列の中でエラーを渡すことができます(' your_form_page.php?errors = Non hai inserito username o password'のように)。それは主に意見に基づく質問です。あなたに最適なものを選んでください。チャオ。 – Federkun
Ciao Federkunあなたの答えに多くの感謝。私はそれを試してみましょう;)grazie – pippo