How to prevent pages from being loaded by the browser after logout

0

I'm trying to make an academic site where users need to log in (login page: pagina.php) and will be directed to the page (nome.php) where the connection is made to the bank and if the registration goes to the page site.php, and then where will logout (logoutt.php), but when I log out and press the browser's back button (instead of directing me to login where I should log in again), is going to the page site.php). If you can help me, thank you.

Note: I'm still learning, this site is more for learning in practice '

Pagina de login:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  </head>
  <body>
     <div class="login">
    <form method="POST" action= 'nome.php'>
<label class="bottom">Login: </label><input type="text" name="login" id="login"><br>
<label>Senha: </label><input type="password" name="senha" id="senha"><br>
<input type="submit" value="login" id="login" name="login">
</form>
  </div>
  
</body>
</html>

pagina enquanto estar logado:

<!DOCTYPE html>
<html>
<head>
	<?php
session_start();
if((!isset ($_SESSION['login'])) and (!isset ($_SESSION['senha'])))
{
    unset($_SESSION['login']);
    unset($_SESSION['senha']);
    header('location:index.php');
    }
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SISTEMA WEB</title>
</head>
 
<body>
<table width="800" height="748" border="1">
  <tr>
    <td height="90" colspan="2" bgcolor="#CCCCCC">SISTEM WEB TESTE
      
	Olá <?$_SESSION['login']?>! <a href="logoutt.php"/>Logout!</a>
    </td>
  </tr>
  <tr>
    <td width="103" height="410" bgcolor="#CCCCCC">MENU AQUI</td>
    <td width="546">CONTEUDO E ICONES AQUI</td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#000000"> </td>
  </tr>
</table>
</body>
</html>

Pagina de logout:

<?php
session_start();
session_unset();
unset($_SESSION["login"]);
unset($_SESSION["senha"]);
session_destroy();
?>
    
asked by anonymous 31.01.2018 / 19:23

1 answer

3

Just put a protection function on every page that should be protected. example

<?php     
  if(!isset($_SESSION['id'])){
    header('Location: /pagina.php');
    exit();
  }    
?>

If there is no $_SESSION['id']; it sends the guy to /pagina.php

As soon as the guy enters the correct login and password, put the database ID of the database in $_SESSION['id']

and when the guy accesses the logou.php just destroy the session using session_detroy(); and then a header('Location: /pagina.php');

    
31.01.2018 / 19:35