Show button if logged in/ hide if not

Asked

Viewed 678 times

0

I want to show the "panel" button if the user is logged in, and if they are not willing to show the login button, and it is possible?

Just follow my code...

<?php

if(isset($_SESSION['usuario'])){
    "echo "<a href="logado.php" class="btn btn-success btn-large">Painel</a>" . "<br>";
}else{

    echo "<a href="login.php" class="btn btn-success btn-large">Login/Entrar</a>" . "<br>";
}



?>
  • You have an extra double quote in your code, here "echo. Remove it. You should also escape the quotes inside the string. See here. Otherwise, the logic is the same.

1 answer

0

Friend, a simple solution would be just using Jquery and CSS, I’ll leave an example below for you.

$('#btn-post').click(function(){

if($('#name').val()  == "Jorge" && $('#mail').val() == "123"){
   $('p').text('Login efetuado,Botão painel visível!') 
   $('#btn-painel').show();
}
else{
  $('#btn-painel').hide();
  $('p').text('Login incorreto, botão não disponível!') 
}
})
#btn-painel{
   display:none;
}
    <div>
        <label for="name">Nome:</label>
        <input type="text" id="name" />
    </div>
    <div>
        <label for="mail">E-mail:</label>
        <input type="email" id="mail" />
    </div>
    <div>
        <label for="msg">Mensagem:</label>
        <textarea id="msg"></textarea>
    </div>
    <div class="button">
        <button id="btn-post">Clique para testar!</button>
        <button id="btn-painel">Painel</button>
        <p></p>
    </div>

<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

To test, type in the field name "Jorge" and in E-mail = "123", just to simulate a login, if the data is this, the button will be visible, if it is not, it will be hidden.

Browser other questions tagged

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