html,css,php编写一个好看的登陆界面
时间: 2024-01-16 13:07:56 浏览: 174
php编写的登陆界面
4星 · 用户满意度95%
好的,我可以给您提供一个简单的登陆界面的示例代码,您可以根据自己的需要进行修改和美化。以下是示例代码:
HTML代码:
```
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="login-box">
<h1>Login</h1>
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter your username">
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password">
<input type="submit" value="Login">
</form>
</div>
</body>
</html>
```
CSS代码:
```
body {
background-color: #f2f2f2;
}
.login-box {
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.2);
padding: 20px;
width: 300px;
margin: auto;
margin-top: 100px;
}
h1 {
text-align: center;
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
}
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;
padding: 10px;
border-radius: 5px;
border: none;
cursor: pointer;
width: 100%;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
```
PHP代码:
```
<?php
// 验证用户名和密码是否正确
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$password = $_POST["password"];
if ($username == "admin" && $password == "123456") {
header("location: welcome.php");
exit();
} else {
$error_msg = "Invalid username or password!";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="login-box">
<h1>Login</h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter your username">
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password">
<input type="submit" value="Login">
<span class="error"><?php echo $error_msg; ?></span>
</form>
</div>
</body>
</html>
```
注意:上述代码只是示例代码,没有进行输入验证和安全性保护,请您在实际开发中一定要注意这些问题。
阅读全文