How to make a box appear when logged in

0

Well, I created a system with $_SESSION , and I would like to know how I could do for example. You have the login, the person logs in to the index, and returns on the same logged in page, and wanted some new things to appear to him, how could he do that?

    
asked by anonymous 19.07.2015 / 14:13

3 answers

1

You can do a check in some field of $ _SESSION with isset. And after that display.

Example:

<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="estilo.css">
<title></title>
</head>
<body>
  <form method="post" action="">
    ...
  </form>

  <?php if ( isset($_SESSION) ){ ?>

  <div>Só será exibido se entrar no if.</div>

  <?php } ?>

</body>
</html>

Documentation: link

    
19.07.2015 / 16:16
0

Explaining: I split my page into small php files (with pure HTML elements) and check if the user is logged in yes the page will be composed with a logout button if not with login and registration buttons.

session_start();
    if((!isset($_SESSION['email']) == true) and (!isset($_SESSION['pass']) == true)){
            require_once 'components/modals/login-modal.php';
            require_once 'components/modals/create-account-modal.php';
        }else{
            require_once 'components/modals/logout-modal.php';
        }
    
19.07.2015 / 16:27
0

After logging, you can write a data to $_SESSION . You can then check if this value exists by using if() and isset() , as suggested by @Allex.

function logar() {
  $_SESSION['logado'] = true;
}

/* ... depois ... */

<?php
  if ( isset($_SESSION['logado']) && $_SESSION['logado'] )
  {
    echo "<b>Coisas especiais.</b>";
  } else {
    echo "<i>Nada especial.</i>";
  }
?>
    
20.07.2015 / 04:42