Finally, I managed to solve my problem, but I'll leave the things explained here to someone who might have the same problem as mine.
In one page of the site I generate 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 generate a link to the same other page with the code:
<a href="http://www.site.com/questao.php?id=1">Reponder</a>
My problem was this, when I used the link that was generated by the PHP script I was redirected to the other page and my session variables retained 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 code above displayed the values passed to the variables when the user logged in.
2 Gabriel Gabriel
But when I used the link I'd put on the page, the session variables were 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>
That way when I click on the link the session variables display the values correctly.
2 Gabriel Gabriel
I do not know why this problem, but I decided that way.
Apparently PHP does not like "www" rs