Home >Backend Development >PHP Tutorial >How to use PHP to develop a user management system in CMS
With the development of the Internet, content management systems (CMS) have become a common tool for website construction, development and management. Among them, the user management system in CMS is very important. The user management system allows website administrators to manage registered users of the website and manage user information, permissions and keys.
In this article, we will introduce how to use PHP to develop the user management system in CMS, let you understand the basic operation and design ideas of the user management system, and help you better implement website user management.
1. Database design
First, we need to design a user data table in the database. This data table is used to store the user’s basic information and permissions, such as user name, password, email, Telephone and other information. Among them, user permissions are divided into administrators and ordinary users. Administrator users have the authority to manage users and various operations, while ordinary users only have access permissions.
The user data table is designed as follows:
CREATE TABLE users
(
id
int(11) NOT NULL AUTO_INCREMENT,
username
varchar(50) NOT NULL,
password
varchar(255) NOT NULL,
email
varchar(255) NOT NULL,
phone
varchar(50) DEFAULT NULL,
type
tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2. User registration page
The user registration page is a form that lists user name, password, email address and other information. User fills in and submits. Behind the scenes, the system receives and validates form data, creates new user accounts, and stores them in the database. The code for the user registration page is as follows:
c3e21731d9b4c344826bcb52eb926b95
100db36a723c770d327fc0aef2ce13b1
93f0f5c25f18dab9d176bd4f6de5d30e
<title>Register - CMS User Management System</title> <link href="style.css" rel="stylesheet">
9c3bca370b5104690d9ef395f2c5f8d1
6c04bd5ca3fcae76e30b72ad730ca86d
<div class="container"> <h1>Register</h1> <form method="post"> <label>Username</label> <input type="text" name="username" required> <label>Password</label> <input type="password" name="password" required> <label>Email</label> <input type="email" name="email" required> <label>Phone</label> <input type="text" name="phone"> <label>Type</label> <select name="type"> <option value="1">Regular User</option> <option value="2">Administrator</option> </select> <button type="submit">Register</button> </form> </div>
36cc49f0c466276486e50c850b7e4956
73a6ac4ed44ffec12cee46588e518a5e
3. User login page
The user login page is used to verify whether the account and password entered by the user can be successfully matched in the database , to ensure that the user is a legitimate user. If the verification is successful, the system redirects the user to the main page of the CMS, if the verification fails, an error message is displayed to the user. The code for the user login page is as follows:
f7a9feed14d3d747334914407eb696cc
100db36a723c770d327fc0aef2ce13b1
93f0f5c25f18dab9d176bd4f6de5d30e
<title>Login - CMS User Management System</title> <link href="style.css" rel="stylesheet">
9c3bca370b5104690d9ef395f2c5f8d1
6c04bd5ca3fcae76e30b72ad730ca86d
<div class="container"> <h1>Login</h1> <?php if (isset($error)): ?> <div class="error"><?php echo $error; ?></div> <?php endif; ?> <form method="post"> <label>Username</label> <input type="text" name="username" required> <label>Password</label> <input type="password" name="password" required> <button type="submit">Login</button> </form> </div>
36cc49f0c466276486e50c850b7e4956
73a6ac4ed44ffec12cee46588e518a5e
4. User management page
The user management page is a core page of CMS, which allows administrators to manage all website users , including adding, editing and deleting user information. Accordingly, the user interface will only allow access and editing of one's own account information. This page also needs to correctly validate and process user-entered data to ensure system security and suitability. The code of the user management page is as follows:
8461146e17606c687e7f0d7a9689d619
aba7b36f87decd50b18c7e3e3c150106
100db36a723c770d327fc0aef2ce13b1
93f0f5c25f18dab9d176bd4f6de5d30e
<title>Manage Users - CMS User Management System</title> <link href="style.css" rel="stylesheet">
9c3bca370b5104690d9ef395f2c5f8d1
6c04bd5ca3fcae76e30b72ad730ca86d
<div class="container"> <h1>Manage Users</h1> <table> <thead> <tr> <th>User ID</th> <th>Username</th> <th>Email</th> <th>Phone</th> <th>User Type</th> <th>Action</th> </tr> </thead> <tbody> <?php // Connect to database $conn = new mysqli("localhost", "root", "password", "database"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // SQL query to select all users $sql = "SELECT * FROM users"; $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['phone'] . "</td>"; if ($row['type'] == 1) { echo "<td>Regular User</td>"; } else { echo "<td>Administrator</td>"; } echo "<td>"; echo "<a href="edit.php?id=" . $row['id'] . "">Edit</a>"; echo " | "; echo "<a href="manage.php?delete=" . $row['id'] . "">Delete</a>"; echo "</td>"; echo "</tr>"; } } else { echo "No users found"; } $conn->close(); ?> </tbody> </table> <a href="register.php">Add user</a> <a href="logout.php">Logout</a> </div>
36cc49f0c466276486e50c850b7e4956
73a6ac4ed44ffec12cee46588e518a5e
5. User editing page
The user editing page allows administrators to edit the current user’s information and also displays the current user’s information. . This page requires proper validation and processing of user input data to ensure data security and suitability. The code for the user editing page is as follows:
282389f58f38e59481e5932eccce4850
aba7b36f87decd50b18c7e3e3c150106
100db36a723c770d327fc0aef2ce13b1
93f0f5c25f18dab9d176bd4f6de5d30e
<title>Edit User - CMS User Management System</title> <link href="style.css" rel="stylesheet">
9c3bca370b5104690d9ef395f2c5f8d1
6c04bd5ca3fcae76e30b72ad730ca86d
<div class="container"> <h1>Edit User</h1> <form method="post"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <label>Username</label> <input type="text" name="username" value="<?php echo $username; ?>" required> <label>Email</label> <input type="email" name="email" value="<?php echo $email; ?>" required> <label>Phone</label> <input type="text" name="phone" value="<?php echo $phone; ?>"> <label>Type</label> <select name="type"> <option value="1" <?php if ($type == 1): ?>selected<?php endif; ?>>Regular User</option> <option value="2" <?php if ($type == 2): ?>selected<?php endif; ?>>Administrator</option> </select> <button type="submit">Save</button> </form> <a href="manage.php">Cancel</a> </div>
36cc49f0c466276486e50c850b7e4956
73a6ac4ed44ffec12cee46588e518a5e
Tips:
Add password strength requirements.
Add verification code to prevent bots.
Force users to choose strong passwords to protect their accounts.
The above is the detailed content of How to use PHP to develop a user management system in CMS. For more information, please follow other related articles on the PHP Chinese website!