0
I’m saving on some valuables using $_SESSION
.
<?php
session_start();
include_once '../controller/LocacaoController.php';
if(!empty($_REQUEST['idfilme']) and !empty($_REQUEST['idfita'])){
$idfilme = $_REQUEST['idfilme'];
$idfita = $_REQUEST['idfita'];
$_SESSION['codfilme'] = $idfilme;
$_SESSION['codfita'] = $idfita;
echo "entrou aqui";
}
else {
if(!empty($_SESSION['codfilme']) and !empty($_SESSION['codfita'])){
$_SESSION['codfita'] = null;
$_SESSION['codfilme'] = null;
}
}
?>
The code is as follows: if in my other file I pass values to $_REQUEST['idfilme']
and $_REQUEST['idfita']
then he enters the IF
and keeps it in Sesssion, Now in case the $_REQUEST
are empty he goes to ELSE
and adds NULL
as $_SESSION['codfita']
and $_SESSION['codfilme']
Ai in another file recover these values:
<?php
session_start();
include_once '../controller/LocacaoController.php';
$idCliente = $_SESSION['cliente'];
$idFita = $_SESSION['codfita'];
$idFilme = $_SESSION['codfilme'];
var_dump($idFita);
var_dump($idFilme);
if(!empty($_SESSION['codfita'])){
$idFita = $_SESSION['codfita'];
$idFilme = $_SESSION['codfilme'];
}
?>
Only the problem is that even though I pass values to $_REQUEST['idfilme']
and $_REQUEST['idfita']
and entering the IF
from Code 1, on the other screen it is returning null
.
NOTE: Do not worry about $_REQUEST
, and linking the files because it is working properly, the problem is the $_SESSION
.
Try to remove your include at first just to test. Maybe you are starting up again or setting something up unexpectedly.
– Oeslei
session_start(); Must be on the first line before any include
– Bruno Almeida