直升機,我犯了一個登錄的話,我想,如果用戶名錯誤,密碼正確則顯示警告,如果用戶名是錯誤的,如果用戶名正確和密碼錯誤則顯示警告,如果密碼是錯誤的,如果用戶名和密碼進行匹配,然後重定向到index.php用戶名檢查和密碼檢查驗證
這是我的腳本
<?php
if(isset($_GET['log'])){
session_start();
session_destroy();
}
$conn = mysqli_connect("localhost","root","","mydb");
$username = isset($_POST["username"]) ? $_POST["username"] : '';
$password = isset($_POST["password"]) ? $_POST["password"] : '';
$password = md5($password);
if($username!='' and $password!=''){
$sql = mysqli_query($conn, "SELECT * from user WHERE username = '$username' AND password = '$password' limit 1");
$data = mysqli_fetch_assoc($sql);
if($data){
session_start();
$_SESSION['username'] = $data['username'];
$_SESSION['password'] = $data['password'];
}
if(isset($_SESSION["username"])){
header('Location: index.php');
}
else {
echo "<script type='text/javascript'>
alert('wrong username and password..!!!');
</script>";
}
}
?>
<body class="" style="background: #fff">
<br><br><br> <br><br><br>
<center></center><br>
<div class="form-box" id="login-box" style="width: 430px;margin-top: -0px;border-radius: 0">
<div class="header" style="background: #2880d7;border-radius: 0">KOPKAR Manunggal Perkasa</div>
<form action="#" method="post">
<div class="body bg-gray">
<div class="form-group">
<input type="text" name="username" class="form-control" placeholder="Username"/>
</div>
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="Password"/>
</div>
</div>
<div class="footer text-center" style="background: #dbdbe0;border-radius: 0">
<button type="submit" name="login" class="btn btn-lg" style="background: #2880d7;color: white;width: 30%">Login</button>
</div>
</form>
</div>
</body>
謝謝
現在你得到任何錯誤? –
你不打算和這個一起生活,是嗎? –
我不明白的錯誤,但我想腳本來檢查,如果用戶名錯誤,密碼正確則顯示警告,如果用戶名是錯誤的,如果用戶名正確和密碼錯誤則顯示警告,如果密碼是錯誤的,如果用戶名和密碼進行匹配,然後重定向到index.php –