Does not close the PHP session

0

I have a question with Sessions in PHP. I have a page called principal.php which is a login and if you do the correct login it takes you to a page called messenger.php, and in the messenger page when closing session does not close it, you can re-enter directly with the link messenger.php

Check to see if the session started:

session_start();
if (isset($_SESSION['login'])) 
{
echo "Bienvenido: " . $_SESSION['login'];
}
else
{
 header("Location: principal.php");
}
<?php
session_start();

// remove all session variables
session_unset(); 

// destroy the session 
session_destroy(); 

header("Location: principal.php")
?>

I close the session but you can still access messenger.php directly with the link without having to log in. Can someone help me please?

    
asked by Javier 29.04.2018 в 01:58
source

1 answer

0

so that you place the session_start () in the logout file, it is assumed that the session is already started.

This can help you:

foreach($_SESSION as $key => $value){
  $_SESSION[$key] = NULL; 
}

session_unset();

session_destroy();

header('Location:'principal.php');
    
answered by 29.04.2018 в 02:49