Empty session variable when redirected

-2

I'm using session variables to check the user logged in to the site.

I have two different links to the same page, one automatically generated by a PHP script through a query in my database. The other one I put on the site myself.

What is happening is the following, when I use the link generated by the query in the database the session variables that I have set retain all their value. But when I use the link I put on the page, all session variables are empty.

Does anyone have any idea what might be happening?

    
asked by anonymous 07.02.2018 / 03:22

1 answer

-2

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

    
07.02.2018 / 03:56