How to box up when logged in

Asked

Viewed 697 times

0

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

3 answers

1

You can do a check in some $_SESSION field 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: http://php.net/manual/en/function.isset.php

  • My function was not compatible with your eating, could you make one for me? Please.

0

Explaining: I divided my page into small php files (with pure HTML elements) and check if the user is logged in if 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';
        }

0

After logging in, you can save a data to $_SESSION. Then you can check if this value exists using a 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>";
  }
?>
  • Da para puxar a informação de quem está online com essa Function?

Browser other questions tagged

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