帮我写一个登陆页面,用户需要输入用户名和密码,以及需要有验证码校验,后端接口是tets/com/api/login ,登录框在屏幕正中间
时间: 2023-05-20 10:03:30 浏览: 104
好的,我可以为您提供一个简单的登陆页面的代码,包括用户名、密码和验证码校验。以下是示例代码:
HTML:
```
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js"></script>
<style>
.container {
margin-top: 50px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Login</h3>
</div>
<div class="panel-body">
<form id="login-form" method="post" action="test/com/api/login">
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="form-group">
<label for="captcha">Captcha</label>
<div class="input-group">
<input type="text" class="form-control" id="captcha" name="captcha" required>
<span class="input-group-addon">
<img src="captcha.php" alt="captcha" onclick="this.src='captcha.php?'+Math.random();" style="cursor:pointer;">
</span>
</div>
</div>
<button type="submit" class="btn btn-primary btn-block">Login</button>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$("#login-form").validate({
rules: {
username: {
required: true
},
password: {
required: true
},
captcha: {
required: true
}
},
messages: {
username: {
required: "Please enter your username"
},
password: {
required: "Please enter your password"
},
captcha: {
required: "Please enter the captcha"
}
}
});
});
</script>
</body>
</html>
```
PHP:
```
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
$captcha = $_POST['captcha'];
if ($captcha != $_SESSION['captcha']) {
echo "Invalid captcha";
exit;
}
// validate username and password
// ...
// if valid, redirect to home page
header("Location: home.php");
exit;
}
?>
```
请注意,这只是一个简单的示例,您需要根据您的具体需求进行修改和完善。
阅读全文