一个基于B/S架构的信息管理系统的用户账户系统的代码
时间: 2024-02-28 08:55:01 浏览: 20
由于一个基于B/S架构的信息管理系统的用户账户系统包含了很多功能,这里无法提供完整的代码。不过,我可以给您提供一个简单的用户注册和登录的示例代码,供您参考。
注册页面代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户注册</title>
</head>
<body>
<form action="register.php" method="post">
<label>用户名:</label><input type="text" name="username"><br>
<label>密码:</label><input type="password" name="password"><br>
<label>确认密码:</label><input type="password" name="confirm_password"><br>
<label>电子邮件:</label><input type="email" name="email"><br>
<label>电话:</label><input type="text" name="phone"><br>
<input type="submit" value="注册">
</form>
</body>
</html>
```
注册处理页面代码(register.php):
```php
<?php
// 获取表单提交的数据
$username = $_POST['username'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
$email = $_POST['email'];
$phone = $_POST['phone'];
// 验证数据的合法性
if (empty($username) || empty($password) || empty($confirm_password) || empty($email) || empty($phone)) {
echo "请填写完整的注册信息!";
exit;
}
if ($password != $confirm_password) {
echo "两次输入的密码不一致!";
exit;
}
// 将用户信息插入数据库中
$conn = mysqli_connect("localhost", "root", "password", "test");
mysqli_query($conn, "set names utf8");
$sql = "INSERT INTO users (username, password, email, phone) VALUES ('$username', '$password', '$email', '$phone')";
$result = mysqli_query($conn, $sql);
if ($result) {
echo "注册成功!";
} else {
echo "注册失败!";
}
mysqli_close($conn);
?>
```
登录页面代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户登录</title>
</head>
<body>
<form action="login.php" method="post">
<label>用户名:</label><input type="text" name="username"><br>
<label>密码:</label><input type="password" name="password"><br>
<input type="submit" value="登录">
</form>
</body>
</html>
```
登录处理页面代码(login.php):
```php
<?php
// 获取表单提交的数据
$username = $_POST['username'];
$password = $_POST['password'];
// 查询数据库中是否有该用户信息
$conn = mysqli_connect("localhost", "root", "password", "test");
mysqli_query($conn, "set names utf8");
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) == 1) {
echo "登录成功!";
} else {
echo "登录失败!";
}
mysqli_close($conn);
?>
```
以上代码仅供您参考,实际开发中需要根据具体需求进行调整和完善。