在PHP中通过admin禁用或停用/激活用户 [英] Disable or deactive / active user by admin in PHP

查看:174
本文介绍了在PHP中通过admin禁用或停用/激活用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.我想通过php在admin中创建禁用或禁用/活动/活动用户.我已经成功了
关于它.但是,我希望用户和管理员以一种形式登录并转到其特定页面.是的,它有效.我调整并添加了针对用户类型(2类型:用于用户和admin)的过程,但是当我在if else语句中添加时,停用功能未起作用,停用用户可以登录到用户页面.您可以检查一下index.php中的其他条件吗?我认为这是问题所在,因为如果我删除用户类型条件,那么状态条件就可以了,但是,如果添加用户类型条件,则用户类型条件有效而无效条件却不起作用.我该怎么办?

对于以下处理良好的用户类型功能,管理员可以转到管理页面,然后用户转到用户页面,但是停用状态不起作用,即使我在管理员中将活动状态更改为停用状态,停用的用户也可以登录.我被困在那里.帮助.谢谢.

我尝试过的事情:

Config.php:

Hi. I want create disable or deactive / active user by admin in php. I already success
about it. However, I want user and admin log in in one form and go to their specific page. Yes, it work. I adjust and add the process for user type (2 type : for user and admin) , however when I add in the if else statement, deactive function did not work and deactive user can login to the user page. Can you check my if else condition in index.php? I think problem on that part because if I remove user type condition then status condition is okay, however if add user type condition, user type condition work yet deactive condition did not work . What should I do?

For below process user type function well, admin go to admin page and user go to user page, however deactive did not work and deactive user can login even I change active to deactive in admin. I stuck there. Help. Thank You.

What I have tried:

Config.php :

<?php
class Database extends pdo {

    private $dbtype; 
    private $host;     
    private $user;
    private $pass; 
    private $database; 

    public function __construct(){ 
        $this->dbtype = ''mysql''; 
        $this->host = ''localhost''; 
        $this->user = ''root''; 
        $this->pass = ''''; 
        $this->database = ''workshire''; 
        $dns = $this->dbtype.'':dbname=''.$this->database.";host=".$this->host; 
        parent::__construct( $dns, $this->user, $this->pass ); 
    }     
}
$database = new Database();
$dbh =& $database;
?>



index.php:



index.php :

<?php
	session_start();
	require_once(''config.php'');
?>
<!DOCTYPE html>
<html>
<head>
	<title>User''s Account Activiation/Deactivation</title>
		<link href="css/bootstrap.css" rel="stylesheet" media="screen">
		<link href="css/bootstrap-responsive.css" rel="stylesheet" media="screen">
		<link rel="stylesheet" type="text/css" href="css/style1.css">
</head>
<body>
<?php

	if(isset($_POST[''submit''])) {
		$user_email = $_POST[''user_email''];
		$access_code = $_POST[''access_code''];
		$result = $dbh->prepare("SELECT * FROM talent_pool WHERE user_email= :user_email AND access_code = :access_code");
		$result->bindParam('':user_email'', $user_email);
		$result->bindParam('':access_code'', $access_code);
		$result->execute();
		$rows = $result->fetch(PDO::FETCH_NUM);
		if($rows > 0) {
			$result=$dbh->prepare("SELECT * FROM talent_pool WHERE user_email=:user_email");
			$result->bindParam('':user_email'', $user_email);
			$result->execute();
			while($row = $result->fetch(PDO::FETCH_ASSOC)){
				$res_id = $row[''id''];
				$curr_status = $row[''status''];
				$roles = $row[''user_type''];
			}
				if($curr_status==''Deactive'') {
					$message = "Sorry $user_email, your account is temporarily deactivated by the admin.";
				}else{
					$_SESSION[''id''] = $res_id;
					header("location: indexEmp.php?logid=$res_id");
				}
				
				if($roles ==''admin'') {
					header("location: admin/index.php?logid=$res_id");
				}else{
					$_SESSION[''id''] = $res_id;
					header("location: indexEmp.php?logid=$res_id");
				}
								
		}
		else{
			$message = ''User Email and Access Code are not exists.'';
		}
	}
?>
<div class="container">
<h1 align="center">User''s LogIn</h1><hr>
	<form method="post" align="center">
		<div class="form-group">
			<label for="name">User Email:</label>
			<input type="text" id="user_email" name="user_email" class="form-control" placeholder="User Email" autofocus required />
		</div>
		<div class="form-group">
			<label for="name">Access Code</label>
			<input type="password" id="access_code" name="access_code" class="form-control" placeholder="Access Code" required>
		</div>
		<div>
			<?php
				if(!empty($message)) {
					echo "<p style=''color: blue; padding: 2px;''>".$message."</p>";
				}
			?>
		</div>
		<input type="submit" name="submit" value="Access Account" class="btn btn-primary"/>
	</form><br/>
</div>
</body>
</html>

推荐答案

dbtype; 私人
dbtype; private


主机; 私人


用户; 私人


这篇关于在PHP中通过admin禁用或停用/激活用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆