Hướng dẫn user management system in php - hệ thống quản lý người dùng trong php

Quản lý người dùng là một phần quan trọng của bất kỳ ứng dụng web nào trong đó người dùng có thể tạo tài khoản và quản lý của họ. Người dùng được phép đăng ký tài khoản của họ và đăng nhập để truy cập vào tài khoản của họ. Người dùng cũng được quản trị viên quản lý để cho phép một số vai trò nhất định hoặc cập nhật thông tin người dùng.

Vì vậy, nếu bạn đang tìm kiếm giải pháp để xây dựng hệ thống quản lý người dùng an toàn thì bạn sẽ ở đây đúng nơi. Trong hướng dẫn này, bạn sẽ tìm hiểu cách tạo hệ thống quản lý người dùng an toàn với PHP và MySQL. Bạn cũng muốn kiểm tra hệ thống đăng nhập và đăng ký với PHP & MySQL để thực hiện đăng nhập và đăng ký người dùng.create secure user management system with PHP and MySQL. You would also like to checkout Login and Registration System with PHP & MySQL to implement user login and registration.

Chúng tôi sẽ triển khai chức năng để quản lý các hoạt động của người dùng như đăng ký người dùng, xác minh email người dùng, đăng nhập, đặt lại mật khẩu và chỉnh sửa hồ sơ. Chúng tôi cũng sẽ tạo bảng quản trị để quản lý người dùng ở cuối quản trị viên để tạo người dùng mới, chỉnh sửa chi tiết người dùng hiện tại và xóa người dùng.

Ngoài ra, đọc:

  • Xây dựng hệ thống trợ giúp với JQuery, PHP & MySQL
  • Xây dựng hệ thống bỏ phiếu trực tuyến với PHP & MySQL
  • Hệ thống quản lý trường học với PHP & MySQL
  • Hệ thống quản lý dự án với PHP và MySQL
  • Hệ thống quản lý bệnh viện với PHP & MySQL

Chúng tôi sẽ đề cập đến hướng dẫn này theo các bước dễ dàng với ví dụ trực tiếp để quản lý người dùng từ Front-end và Quản trị viên.

Vì vậy, hãy để bắt đầu triển khai hệ thống quản lý người dùng với PHP và MySQL. Trước khi chúng tôi bắt đầu, hãy xem cấu trúc tệp cho ví dụ này.

Đăng nhập và đăng ký của người dùng:

  • Đăng ký người dùng với xác minh email.
  • Đăng nhập người dùng với mật khẩu ghi nhớ.
  • Quên mật khẩu & đặt lại mật khẩu.
  • Thông tin người dùng.
  • Hồ sơ người dùng Chỉnh sửa và lưu.

Các tính năng của bảng quản trị:

  • Đăng nhập quản trị viên.
  • Đặt lại mật khẩu quản trị viên.
  • Hồ sơ quản trị.
  • Bảng điều khiển với số liệu thống kê của người dùng.
  • Danh sách người dùng.
  • Thêm người dùng mới với vai trò.
  • Chỉnh sửa và lưu người dùng.
  • Xóa người dùng.

Vì vậy, hãy để bắt đầu triển khai hệ thống quản lý người dùng với PHP và MySQL. Trước khi chúng tôi bắt đầu, hãy xem cấu trúc tệp cho ví dụ này.

  • Đăng nhập và đăng ký của người dùng:: User dashboard
  • Đăng ký người dùng với xác minh email.: Handle User registration.
  • Đăng nhập người dùng với mật khẩu ghi nhớ.: Complete user registration after email verification.
  • Quên mật khẩu & đặt lại mật khẩu.: Handle user login.
  • Thông tin người dùng.: Handle user forget password reset.
  • Hồ sơ người dùng Chỉnh sửa và lưu.: Reset new password.
  • Các tính năng của bảng quản trị:: User profile.
  • Đăng nhập quản trị viên.: edit user profile.
  • Đặt lại mật khẩu quản trị viên.: Class which hold user methods.

Hồ sơ quản trị.

  • Bảng điều khiển với số liệu thống kê của người dùng.: Handle user login
  • Danh sách người dùng.: Display users stats
  • Thêm người dùng mới với vai trò.: Change admin password.
  • Chỉnh sửa và lưu người dùng.: Display admin profile.
  • Xóa người dùng.: Display user list, add new user, edit and delete user.

index.php: bảng điều khiển người dùng

Đăng ký.php: Xử lý đăng ký người dùng.user to store user details to manage users.

CREATE TABLE `user` (
  `id` int(11) NOT NULL,
  `first_name` varchar(50) NOT NULL,
  `last_name` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  `gender` enum('male','female') CHARACTER SET utf8 NOT NULL,
  `mobile` varchar(50) NOT NULL,
  `designation` varchar(50) NOT NULL,
  `image` varchar(250) NOT NULL,
  `type` varchar(250) NOT NULL DEFAULT 'general',
  `status` enum('active','pending','deleted','') NOT NULL DEFAULT 'pending',
  `authtoken` varchar(250) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Xác minh.php: Hoàn thành Đăng ký người dùng sau khi xác minh email.

Đăng nhập.php: Xử lý đăng nhập người dùng.register.php file and handle user registration on form submit.

<div id="signupbox" class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">Sign Up</div>				
		</div>  
		<div class="panel-body" >
			<form id="signupform" class="form-horizontal" role="form" method="POST" action="">				
				<?php if ($message != '') { ?>
					<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $message; ?></div>                            
				<?php } ?>	
				<div class="form-group">
					<label for="firstname" class="col-md-3 control-label">First Name*</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="firstname" placeholder="First Name" value="<?php if(!empty($_POST["firstname"])) { echo $_POST["firstname"]; } ?>" required>
					</div>
				</div>
				<div class="form-group">
					<label for="lastname" class="col-md-3 control-label">Last Name</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="lastname" placeholder="Last Name" value="<?php if(!empty($_POST["lastname"])) { echo $_POST["lastname"]; } ?>" >
					</div>
				</div>					
				<div class="form-group">
					<label for="email" class="col-md-3 control-label">Email*</label>
					<div class="col-md-9">
						<input type="email" class="form-control" name="email" placeholder="Email Address" value="<?php if(!empty($_POST["email"])) { echo $_POST["email"]; } ?>" required>
					</div>
				</div>					
				<div class="form-group">
					<label for="password" class="col-md-3 control-label">Password*</label>
					<div class="col-md-9">
						<input type="password" class="form-control" name="passwd" placeholder="Password" required>
					</div>
				</div>								
				<div class="form-group">						                                  
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-signup" type="submit" name="register" value="register" class="btn btn-info"><i class="icon-hand-right"></i>   Register</button>			
					</div>
				</div>					
				<div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							If You've already an account! 
						<a href="login.php">
							Log In 
						</a>Here
						</div>
					</div>
				</div>  				
			</form>
		 </div>
	</div>
</div>	

forget_password.php: Xử lý người dùng Quên đặt lại mật khẩu.User.php, we will create method register() to implement user registration. We will send an email verification email to user’s email address with link to verify and complete registration.

public function register(){		
	$message = '';
	if(!empty($_POST["register"]) && $_POST["email"] !='') {
		$sqlQuery = "SELECT * FROM ".$this->userTable." 
			WHERE email='".$_POST["email"]."'";
		$result = mysqli_query($this->dbConnect, $sqlQuery);
		$isUserExist = mysqli_num_rows($result);
		if($isUserExist) {
			$message = "User already exist with this email address.";
		} else {			
			$authtoken = $this->getAuthtoken($_POST["email"]);
			$insertQuery = "INSERT INTO ".$this->userTable."(first_name, last_name, email, password, authtoken) 
			VALUES ('".$_POST["firstname"]."', '".$_POST["lastname"]."', '".$_POST["email"]."', '".md5($_POST["passwd"])."', '".$authtoken."')";
			$userSaved = mysqli_query($this->dbConnect, $insertQuery);
			if($userSaved) {				
				$link = "<a href='http://example.com/user-management-system/verify.php?authtoken=".$authtoken."'>Verify Email</a>";			
				$toEmail = $_POST["email"];
				$subject = "Verify email to complete registration";
				$msg = "Hi there, click on this ".$link." to verify email to complete registration.";
				$msg = wordwrap($msg,70);
				$headers = "From: ";
				if(mail($toEmail, $subject, $msg, $headers)) {
					$message = "Verification email send to your email address. Please check email and verify to complete registration.";
				}
			} else {
				$message = "User register request failed.";
			}
		}
	}
	return $message;
}	

reset_password.php: Đặt lại mật khẩu mới.verifyRegister() in class User.php to verify user email to complete registration.

public function verifyRegister(){
	$verifyStatus = 0;
	if(!empty($_GET["authtoken"]) && $_GET["authtoken"] != '') {			
		$sqlQuery = "SELECT * FROM ".$this->userTable." 
			WHERE authtoken='".$_GET["authtoken"]."'";
		$resultSet = mysqli_query($this->dbConnect, $sqlQuery);
		$isValid = mysqli_num_rows($resultSet);	
		if($isValid){
			$userDetails = mysqli_fetch_assoc($resultSet);
			$authtoken = $this->getAuthtoken($userDetails['email']);
			if($authtoken == $_GET["authtoken"]) {					
				$updateQuery = "UPDATE ".$this->userTable." SET status = 'active'
					WHERE id='".$userDetails['id']."'";
				$isUpdated = mysqli_query($this->dbConnect, $updateQuery);					
				if($isUpdated) {
					$verifyStatus = 1;
				}
			}
		}
	}
	return $verifyStatus;
}	

ACCK.php: Hồ sơ người dùng.

edit_account.php: Chỉnh sửa hồ sơ người dùng.login.php file and handle login functionality on form submit.

<div class="col-md-6">                    
	<div class="panel panel-info" >
		<div class="panel-heading">
			<div class="panel-title">Log In</div>                        
		</div> 
		<div style="padding-top:30px" class="panel-body" >
			<?php if ($errorMessage != '') { ?>
				<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $errorMessage; ?></div>                            
			<?php } ?>
			<form id="loginform" class="form-horizontal" role="form" method="POST" action="">                                    
				<div style="margin-bottom: 25px" class="input-group">
					<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
					<input type="text" class="form-control" id="loginId" name="loginId"  value="<?php if(isset($_COOKIE["loginId"])) { echo $_COOKIE["loginId"]; } ?>" placeholder="email">                                        
				</div>                                
				<div style="margin-bottom: 25px" class="input-group">
					<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
					<input type="password" class="form-control" id="loginPass" name="loginPass" value="<?php if(isset($_COOKIE["loginPass"])) { echo $_COOKIE["loginPass"]; } ?>" placeholder="password">
				</div>            
				<div class="input-group">
				  <div class="checkbox">
					<label>
					  <input  type="checkbox" id="remember" name="remember" <?php if(isset($_COOKIE["loginId"])) { ?> checked <?php } ?>> Remember me
					</label>
					<label><a href="forget_password.php">Forget your password</a></label>	
				  </div>
				</div>
				<div style="margin-top:10px" class="form-group">                               
					<div class="col-sm-12 controls">
					  <input type="submit" name="login" value="Login" class="btn btn-info">						  
					</div>						
				</div>
				 <div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							Don't have an account! 
						<a href="register.php">
							Register 
						</a>Here. 
						</div>
					</div>
				</div>    	
			</form>   
		</div>                     
	</div>  
</div>

User.php: lớp giữ các phương thức người dùng.login() in class User.php to handle user login functionality.

public function login(){		
	$errorMessage = '';
	if(!empty($_POST["login"]) && $_POST["loginId"]!=''&& $_POST["loginPass"]!='') {	
		$loginId = $_POST['loginId'];
		$password = $_POST['loginPass'];
		if(isset($_COOKIE["loginPass"]) && $_COOKIE["loginPass"] == $password) {
			$password = $_COOKIE["loginPass"];
		} else {
			$password = md5($password);
		}	
		$sqlQuery = "SELECT * FROM ".$this->userTable." 
			WHERE email='".$loginId."' AND password='".$password."' AND status = 'active'";
		$resultSet = mysqli_query($this->dbConnect, $sqlQuery);
		$isValidLogin = mysqli_num_rows($resultSet);	
		if($isValidLogin){
			if(!empty($_POST["remember"]) && $_POST["remember"] != '') {
				setcookie ("loginId", $loginId, time()+ (10 * 365 * 24 * 60 * 60));  
				setcookie ("loginPass",	$password,	time()+ (10 * 365 * 24 * 60 * 60));
			} else {
				$_COOKIE['loginId' ]='';
				$_COOKIE['loginPass'] = '';
			}
			$userDetails = mysqli_fetch_assoc($resultSet);
			$_SESSION["userid"] = $userDetails['id'];
			$_SESSION["name"] = $userDetails['first_name']." ".$userDetails['last_name'];
			header("location: index.php"); 		
		} else {		
			$errorMessage = "Invalid login!";		 
		}
	} else if(!empty($_POST["loginId"])){
		$errorMessage = "Enter Both user and password!";	
	}
	return $errorMessage; 		
}

Sẽ có các tệp sau đây cho phần quản trị viên để quản lý người dùng.login() to complete user login.

include('class/User.php');
$user = new User();
$message =  $user->login();

index.php: xử lý đăng nhập người dùng

Bảng điều khiển.php: Hiển thị số liệu thống kê của người dùngreset_password.php file to user password. The user email is entered and submitted in forget_password.php and a password reset email will be send to user email address. When user click on password reset link, it will redirect user to reset password form and ask the user to enter new password to save.

<div class="col-md-6">                    
	<div class="panel panel-info" >
		<div class="panel-heading">
			<div class="panel-title">Reset Password</div>                        
		</div> 
		<div style="padding-top:30px" class="panel-body" >
			<?php if ($errorMessage != '') { ?>
				<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $errorMessage; ?></div>                            
			<?php } ?>
			<?php if(!empty($_GET['authtoken']) && $_GET['authtoken']) { ?>
				<form id="loginform" class="form-horizontal" role="form" method="POST" action="">                                    
					<div style="margin-bottom: 25px" class="input-group">
						<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
						<input type="password" class="form-control" id="password" name="password"  placeholder="New password..." required>			
					</div>
					<div style="margin-bottom: 25px" class="input-group">
						<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
						<input type="password" class="form-control" id="cpassword" name="cpassword"  placeholder="Confirm password..." required>              
					</div>	
					<div style="margin-top:10px" class="form-group">                               
						<div class="col-sm-12 controls">
							<input type="hidden" name="authtoken"  value="<?php echo $_GET['authtoken']; ?>" />
							<input type="submit" name="resetpassword" value="Save" class="btn btn-info">						  
						</div>						
					</div>					 
					</div>  	
				</form>
			<?php } else { ?>
				Invalid password reset request.
			<?php } ?>
		</div>                     
	</div>  
</div>

Change_password.php: Thay đổi mật khẩu quản trị viên.resetPassword() in class User.php to send password reset email to user.

public function resetPassword(){
	$message = '';
	if($_POST['email'] == '') {
		$message = "Please enter username or email to proceed with password reset";			
	} else {
		$sqlQuery = "
			SELECT email 
			FROM ".$this->userTable." 
			WHERE email='".$_POST['email']."'";			
		$result = mysqli_query($this->dbConnect, $sqlQuery);
		$numRows = mysqli_num_rows($result);
		if($numRows) {			
			$user = mysqli_fetch_assoc($result);
			$authtoken = $this->getAuthtoken($user['email']);
			$link="<a href='https://www.webdamn.com/demo/user-management-system/reset_password.php?authtoken=".$authtoken."'>Reset Password</a>";				
			$toEmail = $user['email'];
			$subject = "Reset your password on examplesite.com";
			$msg = "Hi there, click on this ".$link." to reset your password.";
			$msg = wordwrap($msg,70);
			$headers = "From: ";
			if(mail($toEmail, $subject, $msg, $headers)) {
				$message =  "Password reset link send. Please check your mailbox to reset password.";
			}				
		} else {
			$message = "No account exist with entered email address.";
		}
	}
	return $message;
}

Hồ sơ.php: Hiển thị hồ sơ quản trị viên.savePassword() in class User.php to save new password.

public function savePassword(){
	$message = '';
	if($_POST['password'] != $_POST['cpassword']) {
		$message = "Password does not match the confirm password.";
	} else if($_POST['authtoken']) {
		$sqlQuery = "
			SELECT email, authtoken 
			FROM ".$this->userTable." 
			WHERE authtoken='".$_POST['authtoken']."'";			
		$result = mysqli_query($this->dbConnect, $sqlQuery);
		$numRows = mysqli_num_rows($result);
		if($numRows) {				
			$userDetails = mysqli_fetch_assoc($result);
			$authtoken = $this->getAuthtoken($userDetails['email']);
			if($authtoken == $_POST['authtoken']) {
				$sqlUpdate = "
					UPDATE ".$this->userTable." 
					SET password='".md5($_POST['password'])."'
					WHERE email='".$userDetails['email']."' AND authtoken='".$authtoken."'";	
				$isUpdated = mysqli_query($this->dbConnect, $sqlUpdate);	
				if($isUpdated) {
					$message = "Password saved successfully. Please <a href='login.php'>Login</a> to access account.";
				}
			} else {
				$message = "Invalid password change request.";
			}
		} else {
			$message = "Invalid password change request.";
		}	
	}
	return $message;
}

user_list.php: Hiển thị danh sách người dùng, thêm người dùng mới, chỉnh sửa và xóa người dùng.

Bước1: Tạo bảng cơ sở dữ liệu MySQLedit_account.php to edit user details and save.

<div id="signupbox" class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">Sign Up</div>				
		</div>  
		<div class="panel-body" >
			<form id="signupform" class="form-horizontal" role="form" method="POST" action="">				
				<?php if ($message != '') { ?>
					<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $message; ?></div>                            
				<?php } ?>	
				<div class="form-group">
					<label for="firstname" class="col-md-3 control-label">First Name*</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="firstname" placeholder="First Name" value="<?php if(!empty($_POST["firstname"])) { echo $_POST["firstname"]; } ?>" required>
					</div>
				</div>
				<div class="form-group">
					<label for="lastname" class="col-md-3 control-label">Last Name</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="lastname" placeholder="Last Name" value="<?php if(!empty($_POST["lastname"])) { echo $_POST["lastname"]; } ?>" >
					</div>
				</div>					
				<div class="form-group">
					<label for="email" class="col-md-3 control-label">Email*</label>
					<div class="col-md-9">
						<input type="email" class="form-control" name="email" placeholder="Email Address" value="<?php if(!empty($_POST["email"])) { echo $_POST["email"]; } ?>" required>
					</div>
				</div>					
				<div class="form-group">
					<label for="password" class="col-md-3 control-label">Password*</label>
					<div class="col-md-9">
						<input type="password" class="form-control" name="passwd" placeholder="Password" required>
					</div>
				</div>								
				<div class="form-group">						                                  
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-signup" type="submit" name="register" value="register" class="btn btn-info"><i class="icon-hand-right"></i>   Register</button>			
					</div>
				</div>					
				<div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							If You've already an account! 
						<a href="login.php">
							Log In 
						</a>Here
						</div>
					</div>
				</div>  				
			</form>
		 </div>
	</div>
</div>	
0

Trước tiên, chúng tôi sẽ tạo người dùng bảng cơ sở dữ liệu MySQL để lưu trữ chi tiết người dùng để quản lý người dùng.editAccount() in class User.php edit and save user profile.

<div id="signupbox" class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">Sign Up</div>				
		</div>  
		<div class="panel-body" >
			<form id="signupform" class="form-horizontal" role="form" method="POST" action="">				
				<?php if ($message != '') { ?>
					<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $message; ?></div>                            
				<?php } ?>	
				<div class="form-group">
					<label for="firstname" class="col-md-3 control-label">First Name*</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="firstname" placeholder="First Name" value="<?php if(!empty($_POST["firstname"])) { echo $_POST["firstname"]; } ?>" required>
					</div>
				</div>
				<div class="form-group">
					<label for="lastname" class="col-md-3 control-label">Last Name</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="lastname" placeholder="Last Name" value="<?php if(!empty($_POST["lastname"])) { echo $_POST["lastname"]; } ?>" >
					</div>
				</div>					
				<div class="form-group">
					<label for="email" class="col-md-3 control-label">Email*</label>
					<div class="col-md-9">
						<input type="email" class="form-control" name="email" placeholder="Email Address" value="<?php if(!empty($_POST["email"])) { echo $_POST["email"]; } ?>" required>
					</div>
				</div>					
				<div class="form-group">
					<label for="password" class="col-md-3 control-label">Password*</label>
					<div class="col-md-9">
						<input type="password" class="form-control" name="passwd" placeholder="Password" required>
					</div>
				</div>								
				<div class="form-group">						                                  
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-signup" type="submit" name="register" value="register" class="btn btn-info"><i class="icon-hand-right"></i>   Register</button>			
					</div>
				</div>					
				<div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							If You've already an account! 
						<a href="login.php">
							Log In 
						</a>Here
						</div>
					</div>
				</div>  				
			</form>
		 </div>
	</div>
</div>	
1

Bước 2: Thực hiện đăng ký người dùng

Chúng tôi sẽ thiết kế mẫu đăng ký người dùng trong tệp đăng ký.php và xử lý đăng ký người dùng trên biểu mẫu.index.php to handle admin login.

<div id="signupbox" class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">Sign Up</div>				
		</div>  
		<div class="panel-body" >
			<form id="signupform" class="form-horizontal" role="form" method="POST" action="">				
				<?php if ($message != '') { ?>
					<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $message; ?></div>                            
				<?php } ?>	
				<div class="form-group">
					<label for="firstname" class="col-md-3 control-label">First Name*</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="firstname" placeholder="First Name" value="<?php if(!empty($_POST["firstname"])) { echo $_POST["firstname"]; } ?>" required>
					</div>
				</div>
				<div class="form-group">
					<label for="lastname" class="col-md-3 control-label">Last Name</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="lastname" placeholder="Last Name" value="<?php if(!empty($_POST["lastname"])) { echo $_POST["lastname"]; } ?>" >
					</div>
				</div>					
				<div class="form-group">
					<label for="email" class="col-md-3 control-label">Email*</label>
					<div class="col-md-9">
						<input type="email" class="form-control" name="email" placeholder="Email Address" value="<?php if(!empty($_POST["email"])) { echo $_POST["email"]; } ?>" required>
					</div>
				</div>					
				<div class="form-group">
					<label for="password" class="col-md-3 control-label">Password*</label>
					<div class="col-md-9">
						<input type="password" class="form-control" name="passwd" placeholder="Password" required>
					</div>
				</div>								
				<div class="form-group">						                                  
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-signup" type="submit" name="register" value="register" class="btn btn-info"><i class="icon-hand-right"></i>   Register</button>			
					</div>
				</div>					
				<div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							If You've already an account! 
						<a href="login.php">
							Log In 
						</a>Here
						</div>
					</div>
				</div>  				
			</form>
		 </div>
	</div>
</div>	
2

Trong lớp user.php, chúng tôi sẽ tạo Phương thức đăng ký () để triển khai đăng ký người dùng. Chúng tôi sẽ gửi email xác minh email đến địa chỉ email của người dùng với liên kết để xác minh và hoàn thành đăng ký.adminLogin() in class User.php to complete admin login.

<div id="signupbox" class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">Sign Up</div>				
		</div>  
		<div class="panel-body" >
			<form id="signupform" class="form-horizontal" role="form" method="POST" action="">				
				<?php if ($message != '') { ?>
					<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $message; ?></div>                            
				<?php } ?>	
				<div class="form-group">
					<label for="firstname" class="col-md-3 control-label">First Name*</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="firstname" placeholder="First Name" value="<?php if(!empty($_POST["firstname"])) { echo $_POST["firstname"]; } ?>" required>
					</div>
				</div>
				<div class="form-group">
					<label for="lastname" class="col-md-3 control-label">Last Name</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="lastname" placeholder="Last Name" value="<?php if(!empty($_POST["lastname"])) { echo $_POST["lastname"]; } ?>" >
					</div>
				</div>					
				<div class="form-group">
					<label for="email" class="col-md-3 control-label">Email*</label>
					<div class="col-md-9">
						<input type="email" class="form-control" name="email" placeholder="Email Address" value="<?php if(!empty($_POST["email"])) { echo $_POST["email"]; } ?>" required>
					</div>
				</div>					
				<div class="form-group">
					<label for="password" class="col-md-3 control-label">Password*</label>
					<div class="col-md-9">
						<input type="password" class="form-control" name="passwd" placeholder="Password" required>
					</div>
				</div>								
				<div class="form-group">						                                  
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-signup" type="submit" name="register" value="register" class="btn btn-info"><i class="icon-hand-right"></i>   Register</button>			
					</div>
				</div>					
				<div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							If You've already an account! 
						<a href="login.php">
							Log In 
						</a>Here
						</div>
					</div>
				</div>  				
			</form>
		 </div>
	</div>
</div>	
3

Chúng tôi sẽ tạo một phương thức VerifyRegister () trong lớp user.php để xác minh email người dùng để hoàn thành đăng ký.

Bước3: Thực hiện đăng nhập người dùngdashboard.php to display users stats in admin dashboard.

<div id="signupbox" class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">Sign Up</div>				
		</div>  
		<div class="panel-body" >
			<form id="signupform" class="form-horizontal" role="form" method="POST" action="">				
				<?php if ($message != '') { ?>
					<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $message; ?></div>                            
				<?php } ?>	
				<div class="form-group">
					<label for="firstname" class="col-md-3 control-label">First Name*</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="firstname" placeholder="First Name" value="<?php if(!empty($_POST["firstname"])) { echo $_POST["firstname"]; } ?>" required>
					</div>
				</div>
				<div class="form-group">
					<label for="lastname" class="col-md-3 control-label">Last Name</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="lastname" placeholder="Last Name" value="<?php if(!empty($_POST["lastname"])) { echo $_POST["lastname"]; } ?>" >
					</div>
				</div>					
				<div class="form-group">
					<label for="email" class="col-md-3 control-label">Email*</label>
					<div class="col-md-9">
						<input type="email" class="form-control" name="email" placeholder="Email Address" value="<?php if(!empty($_POST["email"])) { echo $_POST["email"]; } ?>" required>
					</div>
				</div>					
				<div class="form-group">
					<label for="password" class="col-md-3 control-label">Password*</label>
					<div class="col-md-9">
						<input type="password" class="form-control" name="passwd" placeholder="Password" required>
					</div>
				</div>								
				<div class="form-group">						                                  
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-signup" type="submit" name="register" value="register" class="btn btn-info"><i class="icon-hand-right"></i>   Register</button>			
					</div>
				</div>					
				<div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							If You've already an account! 
						<a href="login.php">
							Log In 
						</a>Here
						</div>
					</div>
				</div>  				
			</form>
		 </div>
	</div>
</div>	
4

Chúng tôi sẽ thiết kế biểu mẫu đăng nhập người dùng trong tệp đăng nhập và xử lý chức năng đăng nhập trên biểu mẫu gửi.

Chúng tôi sẽ tạo một phương thức đăng nhập () trong lớp user.php để xử lý chức năng đăng nhập người dùng.user_list.php to display users list in Datatable. We will design modal to add and edit user. Als handle muser delete functionality.

<div id="signupbox" class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">Sign Up</div>				
		</div>  
		<div class="panel-body" >
			<form id="signupform" class="form-horizontal" role="form" method="POST" action="">				
				<?php if ($message != '') { ?>
					<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $message; ?></div>                            
				<?php } ?>	
				<div class="form-group">
					<label for="firstname" class="col-md-3 control-label">First Name*</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="firstname" placeholder="First Name" value="<?php if(!empty($_POST["firstname"])) { echo $_POST["firstname"]; } ?>" required>
					</div>
				</div>
				<div class="form-group">
					<label for="lastname" class="col-md-3 control-label">Last Name</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="lastname" placeholder="Last Name" value="<?php if(!empty($_POST["lastname"])) { echo $_POST["lastname"]; } ?>" >
					</div>
				</div>					
				<div class="form-group">
					<label for="email" class="col-md-3 control-label">Email*</label>
					<div class="col-md-9">
						<input type="email" class="form-control" name="email" placeholder="Email Address" value="<?php if(!empty($_POST["email"])) { echo $_POST["email"]; } ?>" required>
					</div>
				</div>					
				<div class="form-group">
					<label for="password" class="col-md-3 control-label">Password*</label>
					<div class="col-md-9">
						<input type="password" class="form-control" name="passwd" placeholder="Password" required>
					</div>
				</div>								
				<div class="form-group">						                                  
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-signup" type="submit" name="register" value="register" class="btn btn-info"><i class="icon-hand-right"></i>   Register</button>			
					</div>
				</div>					
				<div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							If You've already an account! 
						<a href="login.php">
							Log In 
						</a>Here
						</div>
					</div>
				</div>  				
			</form>
		 </div>
	</div>
</div>	
5

Chúng tôi sẽ tạo tệp JavaScript Users.js để xử lý tải dữ liệu DataTable, xử lý thêm, chỉnh sửa và xóa các bản ghi.users.js to handle Datatable data load, handle add, edit and delete records.

<div id="signupbox" class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">Sign Up</div>				
		</div>  
		<div class="panel-body" >
			<form id="signupform" class="form-horizontal" role="form" method="POST" action="">				
				<?php if ($message != '') { ?>
					<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $message; ?></div>                            
				<?php } ?>	
				<div class="form-group">
					<label for="firstname" class="col-md-3 control-label">First Name*</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="firstname" placeholder="First Name" value="<?php if(!empty($_POST["firstname"])) { echo $_POST["firstname"]; } ?>" required>
					</div>
				</div>
				<div class="form-group">
					<label for="lastname" class="col-md-3 control-label">Last Name</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="lastname" placeholder="Last Name" value="<?php if(!empty($_POST["lastname"])) { echo $_POST["lastname"]; } ?>" >
					</div>
				</div>					
				<div class="form-group">
					<label for="email" class="col-md-3 control-label">Email*</label>
					<div class="col-md-9">
						<input type="email" class="form-control" name="email" placeholder="Email Address" value="<?php if(!empty($_POST["email"])) { echo $_POST["email"]; } ?>" required>
					</div>
				</div>					
				<div class="form-group">
					<label for="password" class="col-md-3 control-label">Password*</label>
					<div class="col-md-9">
						<input type="password" class="form-control" name="passwd" placeholder="Password" required>
					</div>
				</div>								
				<div class="form-group">						                                  
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-signup" type="submit" name="register" value="register" class="btn btn-info"><i class="icon-hand-right"></i>   Register</button>			
					</div>
				</div>					
				<div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							If You've already an account! 
						<a href="login.php">
							Log In 
						</a>Here
						</div>
					</div>
				</div>  				
			</form>
		 </div>
	</div>
</div>	
6

Chúng tôi sẽ tạo Phương thức GetUserList () trong lớp user.php để lấy danh sách người dùng và trả về dưới dạng dữ liệu JSON để hiển thị trong DataTables.getUserList() in class User.php to get user list and return as JSON data to display in Datatables.

<div id="signupbox" class="col-md-7">
	<div class="panel panel-info">
		<div class="panel-heading">
			<div class="panel-title">Sign Up</div>				
		</div>  
		<div class="panel-body" >
			<form id="signupform" class="form-horizontal" role="form" method="POST" action="">				
				<?php if ($message != '') { ?>
					<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $message; ?></div>                            
				<?php } ?>	
				<div class="form-group">
					<label for="firstname" class="col-md-3 control-label">First Name*</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="firstname" placeholder="First Name" value="<?php if(!empty($_POST["firstname"])) { echo $_POST["firstname"]; } ?>" required>
					</div>
				</div>
				<div class="form-group">
					<label for="lastname" class="col-md-3 control-label">Last Name</label>
					<div class="col-md-9">
						<input type="text" class="form-control" name="lastname" placeholder="Last Name" value="<?php if(!empty($_POST["lastname"])) { echo $_POST["lastname"]; } ?>" >
					</div>
				</div>					
				<div class="form-group">
					<label for="email" class="col-md-3 control-label">Email*</label>
					<div class="col-md-9">
						<input type="email" class="form-control" name="email" placeholder="Email Address" value="<?php if(!empty($_POST["email"])) { echo $_POST["email"]; } ?>" required>
					</div>
				</div>					
				<div class="form-group">
					<label for="password" class="col-md-3 control-label">Password*</label>
					<div class="col-md-9">
						<input type="password" class="form-control" name="passwd" placeholder="Password" required>
					</div>
				</div>								
				<div class="form-group">						                                  
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-signup" type="submit" name="register" value="register" class="btn btn-info"><i class="icon-hand-right"></i>   Register</button>			
					</div>
				</div>					
				<div class="form-group">
					<div class="col-md-12 control">
						<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
							If You've already an account! 
						<a href="login.php">
							Log In 
						</a>Here
						</div>
					</div>
				</div>  				
			</form>
		 </div>
	</div>
</div>	
7

Bạn cũng có thể thích:

  • Xây dựng hệ thống trợ giúp với JQuery, PHP & MySQL
  • Xây dựng hệ thống bỏ phiếu trực tuyến với PHP & MySQL
  • Hệ thống quản lý trường học với PHP & MySQL
  • DataTables Thêm Xóa chỉnh sửa với Codeigniter
  • Tạo API RESTful bằng cách sử dụng Codeigniter
  • Xây dựng tập lệnh captcha có thể tái sử dụng với PHP
  • Lọc tìm kiếm sản phẩm bằng Ajax, PHP & MySQL
  • Tải lên hình ảnh và cắt theo phương thức với JQuery, PHP & MySQL
  • Xây dựng hệ thống thông báo đẩy với PHP & MySQL
  • Hệ thống quản lý dự án với PHP và MySQL
  • Hệ thống quản lý bệnh viện với PHP & MySQL
  • Xây dựng hệ thống bản tin với PHP và MySQL
  • Hiệu ứng tải màn hình bộ xương với AJAX và PHP
  • Xây dựng diễn đàn thảo luận với PHP và MySQL
  • Hệ thống quản lý quan hệ khách hàng (CRM) với PHP & MySQL
  • Hệ thống thi trực tuyến với PHP & MySQL
  • Hệ thống quản lý chi phí với PHP & MySQL

Bạn có thể xem bản demo trực tiếp từ liên kết demo và có thể tải xuống tập lệnh từ liên kết tải xuống bên dưới. Tải xuống Demo Demo Demo Demo
Admin Demo User Demo Download