用html代码写一个登录和注册页面
时间: 2024-01-29 10:03:41 浏览: 21
<!DOCTYPE html>
<html>
<head>
<title>Login and Registration Form</title>
<style type="text/css">
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
form {
margin: 0 auto;
width: 400px;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px #ccc;
}
h2 {
text-align: center;
margin-bottom: 30px;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
border-radius: 5px;
border: none;
margin-bottom: 20px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
border: none;
padding: 10px;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
.error {
color: red;
margin-bottom: 10px;
}
.success {
color: green;
margin-bottom: 10px;
}
</style>
</head>
<body>
<form action="" method="post">
<h2>Login Form</h2>
<?php if(!empty($login_error)) { ?>
<p class="error"><?php echo $login_error; ?></p>
<?php } ?>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="Login">
</form>
<form action="" method="post">
<h2>Registration Form</h2>
<?php if(!empty($registration_error)) { ?>
<p class="error"><?php echo $registration_error; ?></p>
<?php } ?>
<?php if(!empty($registration_success)) { ?>
<p class="success"><?php echo $registration_success; ?></p>
<?php } ?>
<label for="reg_username">Username:</label>
<input type="text" id="reg_username" name="reg_username" required>
<label for="reg_password">Password:</label>
<input type="password" id="reg_password" name="reg_password" required>
<label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password" required>
<input type="submit" value="Register">
</form>
</body>
</html>
注:这是一个简单的登录和注册页面,包含了HTML和PHP代码。PHP代码用于验证登录和注册信息。要使此代码工作,需要将其保存为.php文件并将相关的PHP代码添加到原始代码中。