Create and destroy session

1

Good morning!

I have a question about session. For example, I'm developing a system where I have 3 environments. The first is the virtual store environment and the other two environments are virtual, type, Reseller and Retail office. The latter two are restricted areas. So, do I need to create a session for each of these environments when the various users access? That is, does each user need to generate a single session with each access, after I destroy it? For example, I'm having a problem with my shopping cart. The online store contains a shopping cart. When closing, I need to destroy the session, but at the end of my shopping cart and generate the invoice.pdf, then I destroy the session, but it does not destroy.

Regarding the shopping cart I'm doing this:

cart.php - where do I create the session

Destroying the carton session after generating the invoice.pdf: Still inside the cart cart.php // destroying the session cart ... include ("destroi_sessao_carrinho.php");

file: destroi_sessao_carrinho.php

I need a light. Where am I going wrong. Thanks in advance.

    
asked by anonymous 16.05.2018 / 14:48

1 answer

2

Creating a constraint level in the users table, for example, you get the result. When the user logs in, you search for this level of access and create the session with it:

$_SESSION['nivel_acesso']=$nivel_acesso;

In the pages where he can not enter you do a verification:

if((!isset($_SESSION['nivel_acesso']))||($_SESSION['nivel_acesso']!=1)):// 1 seria o nivel necessario
    header('location: redirecionamento');//aqui você redirecionada para onde ele vai caso não tenha nivel de acesso
endif;

In the file destroi_sessao_carrinho.php :

<?php
session_start();//session_start() deve ser chamado antes de tudo
if(isset($_SESSION['carrinho'])):
    unset($_SESSION['carrinho']); 
    session_destroy(); 
    header("Location: produtos.php"); 
    exit();
endif;
?>
    
16.05.2018 / 14:55