User privileges

Asked

Viewed 156 times

0

Well, I’m on a college exercise that’s creating a blog. Can contain 4 different users: User(only reads post and comments) Redator(Creates posts and manages comments) ADM(manages all posts and comments) ADM General total system control (create, edit.delete any element including users and permissions)

To create post, change permissions etc, you need a navigation bar on the site, my question is: How can I make appear the corresponding options in the bar for each user?

<?php
session_start();
$_SESSION["new"]="limitado";
require_once('BdClass.php');
if(isset($_GET['login']) and isset($_GET['senha'])){
$objBd = new bd();
$objBd->conecta_mysql();
$param= array();
array_push($param, $_GET['login']);
array_push($param, $_GET['senha']);
$sql="SELECT nome,senha,id,tipo from usuario where nome=? and senha=? and ativo = 1;";
$result=$objBd->exec($sql,'ss',$param);
$valor=mysqli_fetch_array($result);
if(isset($valor['nome'])){
    $_SESSION["nome"]=$valor['nome'];
    $_SESSION["senha"]=$valor['senha'];
    $_SESSION["id"]=$valor['id'];
    $_SESSION["tipo"]=$valor['tipo'];
    $_SESSION["ativo"] = 1;
    header("location:1.html");
}
else{
     echo "<script>alert('Se cadastre antes para logar no site');</script>";
 }
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="estilo.css">
    <title>INICIO</title>
</head>
<body>
<ul>
  <li><a href="Pagi.php">Oh...Blooog!</a></li>
  <<li><a href="Login.php">Cadastro</a></li>
  <!--<li><a href="apagar.php">Apagar a Merda do Meu Cadastro!</a></li>-->
  <!--<li><a href="index.php">Sair Desta Bosta de Site</a></li>-->
  <!--<li><a href="bf.html">&Ocirc; Bibsfiha</a></li>-->
</ul>
<form method="GET" action="Login.php">
    <label>Nome: </label>
    <div><input type="text" name="login" value="">
    </div>
    <label>Senha: </label>
    <div><input type="password" name="senha">
    </div>
    <div><input type="submit" name="ok">
    </div>
</form>
</body>
</html>
  • Put the code you’ve already done, and point out what the problem is.

  • Post what you already have or tried to do to help us

  • You will need to use conditionals IF... To verify the type of user, will you use any database? You can show us in code form what you’ve tried so it’s easier to help you

1 answer

1

You can do this in many ways.

I’ll show you a very simple example using php session as user identifier:

<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-
toggle="collapse" data-target="#navbarSupportedContent" aria-
controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle     navigation">
<span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="#">Navbar</a>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
<?php session_start(); if($_SESSION['usuario_admin']!=''){ ?>
      <li class="nav-item active">
    <a class="nav-link" href="#">Postar <span class="sr-only">(current)</span>    </a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Comentar</a>
  </li>
 <? }
elseif (...) // escrever  outras condições
 ?>
// escrever otras funções de acordo com cada tipo de usuário
</ul>
<form class="form-inline my-2 my-lg-0">
  <input class="form-control mr-sm-2" type="text" placeholder="Search">
  <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
  </div>
</nav>

I hope I helped, hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.