Anyway, I managed to solve my problem, but I’m going to leave things better explained here to someone who might have the same problem as mine.
On one page of the website the link to another by the following script:
<?php
//Verifica as questões do relatório disponíveis no banco de dados
$query = "SELECT idquestao, numquestao FROM questao WHERE relatorio_idrelatorio = '"
. $_GET['id'] . "' ORDER BY numquestao";
$result = mysqli_query($link, $query);
while ($linha = mysqli_fetch_array($result)) {
$acessar = "http://www.site.com/questao.php?id=" . $linha['idquestao'];
echo "<li><a href='" . $acessar . "'>Atividade " . $linha['numquestao'] . "</a></li>";
}
?>
And on that same page I link to the same other page by the code:
<a href="http://www.site.com/questao.php?id=1">Reponder</a>
My problem was this, when using the link that was generated by the PHP script was redirected to the other page and my session variables kept their values.
<?php
session_start();
if (!$_SESSION['id'] || !$_SESSION['nome'] || !$_SESSION['usuario']) {
//header("Location:http://www.site.com/?erro=2");
}
echo $_SESSION['id'];
echo $_SESSION['nome'];
echo $_SESSION['usuario'];
?>
So the above code displayed the values passed to the variables when the user logged in.
2 Gabriel Gabriel
But when I used the link I had put on the page myself, the session variables appeared empty.
The way the problem was solved was just removing the "www" from the beginning of the link
<a href="http://site.com/questao.php?id=1">Reponder</a>
So when I click on the link the session variables present the values correctly.
2 Gabriel Gabriel
I don’t know why I had a problem, but I solved it that way.
Apparently PHP doesn’t like "www" rs
Hello Open, no code has no way to solve your problem.
– Alex
Is using
session_start();
on all pages?– Valdeir Psr
Hi Marcelo, I put the code summarized below
– Gabriel Castro
Use
session_start();
on all pages yes– Gabriel Castro