用php和css写一个登录界面
时间: 2024-06-05 09:06:42 浏览: 44
登陆界面与权限管理.zip_权限_登陆界面与权限管理
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<style>
body {
background-color: #f7f7f7;
font-family: Arial, sans-serif;
}
.container {
margin: 0 auto;
max-width: 500px;
padding: 50px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0px 0px 5px #999;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
input[type=text], input[type=password] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: none;
border-radius: 3px;
background-color: #f2f2f2;
font-size: 16px;
color: #333;
}
input[type=submit] {
background-color: #333;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}
input[type=submit]:hover {
background-color: #555;
}
.error {
color: red;
font-size: 14px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="container">
<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">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<input type="submit" value="Login">
</form>
<?php
$username = $password = "";
$usernameErr = $passwordErr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["username"])) {
$usernameErr = "Username is required";
} else {
$username = test_input($_POST["username"]);
}
if (empty($_POST["password"])) {
$passwordErr = "Password is required";
} else {
$password = test_input($_POST["password"]);
}
if (!empty($username) && !empty($password)) {
// Perform database authentication here
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<span class="error"><?php echo $usernameErr; ?></span>
<span class="error"><?php echo $passwordErr; ?></span>
</div>
</body>
</html>
阅读全文