Leonardo Vianello
Leonardo Vianello

Reputation: 1

Session variables are not saved / Session get destroyed - in SiteGround

I implemented a management site in PHP where access to the ID is saved in a session variable ($_SESSION['user']). Still, after I was redirected to another page with a header, the session variable seemed empty on the other page.

I'm sure that the code is written correctly because it works in localhost with XAMPP; in every php page, the session is started at the first line ("session_start();"); the PHP version in SiteGround is the same as the XAMPP version.

At this point I read like 50 blogs and I can't find a solution. I think that the problem is SiteGround because many person in various blogs had the same problem.

I attach the semplified code that I used to try to solve this problem.

INDEX:

<?php
    session_start();
?>
<html>
    <form action="login.php" method="POST">
        <input type="text" name="t">
        <input type="number" name="n">
        <input type="submit" value="Send">
    </form>
</html>

LOGIN PAGE:

<?php
    session_start();
    $_POST['t'] = $_SESSION['t'];
    $_POST['p'] = $_SESSION['p'];
    session_write_close();
    header("Location: entered.php");
?>

ENTERED PAGE:

<?php
    session_start();
    echo $_SESSION['t'];
    echo $_SESSION['p'];
?>

Upvotes: 0

Views: 28

Answers (0)

Related Questions