1
0
Fork 0
php-coding/12.test2.login.php

83 lines
2.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
session_start();
if (!empty($_POST['submit'])) {
$check = $_POST['check'];
if (strtolower(trim($check)) == strtolower($_SESSION['check_checks'])) {
echo '<script>alert("登陆成功");window.location.href="https://bing.com"</script>';
} else {
echo '<script>alert("验证码错误");window.location.href="12.test2.login.php"</script>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<form method="post" action="">
<table>
<tr>
<th colspan="2" style="text-align: center">
<h1>用户登录</h1>
</th>
</tr>
<tr>
<td>
<label for="username1">用户名</label>
</td>
<td>
<input type="text" id="username1" name="username" required>
</td>
</tr>
<tr>
<td>
<label for="password1">密码</label>
</td>
<td>
<input type="password" name="password" id="password1" required>
</td>
</tr>
<tr>
<td>
<label for="check1">验证码</label>
</td>
<td>
<img src="12.test2.checks.php" alt="验证码" onclick="refresh_check()" id="captchaImage">
<input type="text" name="check" id="check1" required size=9>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<input type="submit" value="登录" name="submit" id="submit1" onclick="return check()">
<input type="reset" value="重置" name="reset" id="reset1" onclick="refresh_check()">
</td>
</tr>
</table>
</form>
<script>
function refresh_check() {
// 获取验证码图像元素
var captchaImage = document.querySelector('#captchaImage');
// 生成新的时间戳,用于强制刷新图像
var timestamp = new Date().getTime();
// 修改验证码图像的src属性添加时间戳参数
captchaImage.src = '12.test2.checks.php?timestamp=' + timestamp;
}
function check() {
//check username and password empty
const username = document.getElementById("username1").value;
const password = document.getElementById("password1").value;
const check = document.getElementById("check1").value;
if (username === "" || password === "" || check === "") {
alert("用户名或密码或验证码不能为空!");
return false;
}
}
</script>
</body>