Session not holding value

Asked

Viewed 67 times

2

My SESSION is not storing the values during its useful life. Here I used to demonstrate a var_dump:

var_dump($_SESSION);
    array (size=3)
      'no_pessoa' => string 'Wander Carlos' (length=15)
      'cd_pessoa' => string '1' (length=1)
      'cd_uploadfoto' => int 0

About five minutes later she’s like this:

var_dump($_SESSION);
array (size=3)
  'no_pessoa' => string 'b:0;' (length=4)
  'cd_pessoa' => string 'b:0;' (length=4)
  'cd_uploadfoto' => string 'b:0;' (length=4)

The Session is set only once, where the login will be validated, then the user is redirected to the system.

<?php
    session_start();
    include_once 'function/funcoes.php';
    require_once 'DB.php';
    $login = $_REQUEST ['username'];
    $senha = $_REQUEST ['password'];

    $login = tratarSqlInjection($login);
    $senha = tratarSqlInjection($senha);

    $senha = md5($senha);

    $consulta = DB::prepare("select * from tb_pessoa p
                                join tb_usuario u using(cd_pessoa)
                                join tb_permissao pp using(cd_permissao)
                                join tb_login l using (cd_login) where l.no_login = :login and l.senha = :senha and bo_ativo = 1");

    $consulta->bindValue(':login', $login);
    $consulta->bindValue(':senha', $senha);
    $consulta->execute();
    $linha = $consulta->fetch(PDO::FETCH_OBJ);
    if (isset($linha->cd_usuario)) {
        $_SESSION ['no_pessoa'] = $linha->no_nome;
        $_SESSION ['cd_pessoa'] = $linha->cd_pessoa;
        $_SESSION['cd_uploadfoto'] = 0;
        if (isset($_SESSION['url'])) {
            header("Location:{$_SESSION['url']}");
        } else {
            ?>
            <script language= "JavaScript">
                location.href = "index.php"
            </script>
            <?php
            header("Location:index.php");
        }
        exit();
    } else {
        alerta("ATENÇÃO! Usuário ou Senha inválida.");
        voltar();
        exit();
    }

Follows admin system.

<?php session_start(); ?>
<html>
    <head>
        <?php require 'assets/include/css.php'; ?>
    </head>
    <body class="page-header-fixed page-quick-sidebar-over-content">
        <?php
        require_once 'restrito.php';
        require_once 'DB.php';
        require_once 'function/funcoes.php';
        require_once 'autoload/autoload.php';
        ?>
        <div class="page-container">
            <?php
            $box = new box();
            require 'layout/menutopo/menu.php';
            require 'layout/menuleft/menu.php';
            ?>
            <div class="page-content-wrapper">
                <div class="page-content">
                    <?php
                    require 'layout/navegacao.php';
                    require 'controladorpaginas.php';
                    include_once '../loader.php';
                    ?>
                </div>
                <?php require 'assets/include/script.php'; ?>

            </div>
        </div>

        <?php modalBootstrap() ?>
    </body>
</html>
  • And what is your code that defines the sessions and how you are working with them?

  • Are you starting the session where you want her to "hold it"? session_start()

  • @Rafaelaugusto I am. the system does not leave the index at the beginning of it I start the session

No answers

Browser other questions tagged

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