Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Rodrigo5468

eu gostaria de bloquear algumas páginas

Recommended Posts

Olá,

 

Bom, a passar do tempo eu venho estudando muito pra conseguir terminar um projeto. Estou quais lá, falta apenas algumas coisas, e vocês sempre me ajuda tirando as minhas dúvidas. Acredito que termino o projeto com essas dúvidas respondidas.

Fiz um crud, ele está inserindo normalmente no banco de dados, ler, edita, excluí e atualiza. Tudo okay. No Login.php eu tenho a sessão $_SESSION['admin'] = $row['PAdministrador']; e no banco de dados.

36I8gOK.png

Ele vem nulo como padrão, isso seria os níveis de acesso, eu gostaria de bloquear algumas páginas. Porem eu acho que estou certo, porem não está indo, olha como estou tentando.

<?php
if($_SESSION['admin'] <= 0){
	return false;
	header('location:./');
}else{
	return true;
}
?>
Coloquei isso em cima do <html>.

 

A outra dúvida é, como eu faço um perfil para esses membros? Para eles e os administradores visualizar e editar alguns campos?

 

 

Se alguém poder me ajudar eu agradeceria muito!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Está aqui as funções do crud

<?php
require_once 'banco.php';

abstract class Crud extends banco {
	
	protected $table;
	
	abstract public function insert();
	abstract public function update($id);
	
	public function find($id) {
		$sql = "SELECT * FROM $this->table WHERE id = :id";
		$stmt = banco::prepare($sql);
		$stmt->bindParam(':id', $id, PDO::PARAM_INT);
		$stmt->execute();
		return $stmt->fetch();
	}
	
	public function findAll() {
		$sql = "SELECT * FROM $this->table";
		$stmt = banco::prepare($sql);
		$stmt->execute();
		return $stmt->fetchAll();
	}
	
	public function delete($id) {
		$sql = "DELETE FROM $this->table WHERE id = :id";
		$stmt = banco::prepare($sql);
		$stmt->bindParam(':id', $id, PDO::PARAM_INT);
		return $stmt->execute();
	}
}
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eu conseguir fazer o perfil para os membros e administradores.

Só que não estou conseguindo bloquear algumas páginas.

<?php
/**
 * Class login
 * handles the user's login and logout process
 */
class Login
{
    /**
     * @var object The database connection
     */
    private $db_connection = null;
    /**
     * @var array Collection of error messages
     */
    public $errors = array();
    /**
     * @var array Collection of success / neutral messages
     */
    public $messages = array();
    /**
     * the function "__construct()" automatically starts whenever an object of this class is created,
     * you know, when you do "$login = new Login();"
     */
    public function __construct()
    {
        // create/read session, absolutely necessary
        session_start();
        // check the possible login actions:
        // if user tried to log out (happen when user clicks logout button)
        if (isset($_GET["logout"])) {
            $this->doLogout();
        }
        // login via post data (if user just submitted a login form)
        elseif (isset($_POST["login"])) {
            $this->dologinWithPostData();
        }
    }
    /**
     * log in with post data
     */
    private function dologinWithPostData()
    {
        // check login form contents
        if (empty($_POST['user_name'])) {
            $this->errors[] = "Username field was empty.";
        } elseif (empty($_POST['user_password'])) {
            $this->errors[] = "Password field was empty.";
        } elseif (!empty($_POST['user_name']) && !empty($_POST['user_password'])) {
            // create a database connection, using the constants from config/db.php (which we loaded in index.php)
            $this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
            // change character set to utf8 and check it
            if (!$this->db_connection->set_charset("utf8")) {
                $this->errors[] = $this->db_connection->error;
            }
            // if no connection errors (= working database connection)
            if (!$this->db_connection->connect_errno) {
                // escape the POST stuff
                $user_name = $this->db_connection->real_escape_string($_POST['user_name']);
                // database query, getting all the info of the selected user (allows login via email address in the
                // username field)
                $sql = "SELECT user_name, user_email, user_password_hash
                        FROM users
                        WHERE user_name = '" . $user_name . "' OR user_email = '" . $user_name . "';";
                $result_of_login_check = $this->db_connection->query($sql);
                // if this user exists
                if ($result_of_login_check->num_rows == 1) {
                    // get result row (as an object)
                    $result_row = $result_of_login_check->fetch_object();
                    // using PHP 5.5's password_verify() function to check if the provided password fits
                    // the hash of that user's password
                    if (password_verify($_POST['user_password'], $result_row->user_password_hash)) {
                        // write user data into PHP SESSION (a file on your server)
                        $_SESSION['user_name'] = $result_row->user_name;
                        $_SESSION['user_email'] = $result_row->user_email;
                        $_SESSION['user_login_status'] = 1;
                    } else {
                        $this->errors[] = "Wrong password. Try again.";
                    }
                } else {
                    $this->errors[] = "This user does not exist.";
                }
            } else {
                $this->errors[] = "Database connection problem.";
            }
        }
    }
    /**
     * perform the logout
     */
    public function doLogout()
    {
        // delete the session of the user
        $_SESSION = array();
        session_destroy();
        // return a little feeedback message
        $this->messages[] = "You have been logged out.";
    }
    /**
     * simply return the current state of the user's login
     * @return boolean user's login status
     */
    public function isUserLoggedIn()
    {
        if (isset($_SESSION['user_login_status']) AND $_SESSION['user_login_status'] == 1) {
            return true;
        }
        // default return
        return false;
    }
}

Queria fazer uma sessão do PAdministrador se ele for menor ou igual a zero ele não consegue visualizar caso contrario ele tem acesso. Alguém me ajuda?

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.