以下是一个简单的PHP登录界面的代码示例:
<!DOCTYPE html>
<html>
<head>
<title>登录界面</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
}
.container {
width: 300px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
.container h2 {
margin-top: 0;
}
.container input[type="text"],
.container input[type="password"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.container input[type="submit"] {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
.container input[type="submit"]:hover {
background-color: #45a049;
}
.error {
color: #FF0000;
margin-bottom: 10px;
}
</style>
</head>
<body>
<?php
// 定义变量并初始化为空
$username = $password = "";
$usernameErr = $passwordErr = "";
// 处理表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 验证用户名
if (empty($_POST["username"])) {
$usernameErr = "用户名不能为空";
} else {
$username = test_input($_POST["username"]);
}
// 验证密码
if (empty($_POST["password"])) {
$passwordErr = "密码不能为空";
} else {
$password = test_input($_POST["password"]);
}
// 如果用户名和密码都不为空,则进行登录验证
if (!empty($username) && !empty($password)) {
// 在此处添加登录验证的代码
// ...
}
}
// 用于处理输入数据的函数
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div class="container">
<h2>登录</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<input type="text" name="username" placeholder="用户名">
<span class="error"><?php echo $usernameErr; ?></span>
<br>
<input type="password" name="password" placeholder="密码">
<span class="error"><?php echo $passwordErr; ?></span>
<br>
<input type="submit" value="登录">
</form>
</div>
</body>
</html>
这个代码示例包含了一个简单的登录界面,其中包含了一个用户名输入框、一个密码输入框和一个登录按钮。在表单提交时,会进行用户名和密码的验证,并在输入不符合要求时显示错误信息。你可以根据需要进行修改和扩展。
下一篇:pchar php
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站