1

I'm trying to create a mock-up of a site with the ability of logging in using PHP and session.

menu.php

<ul>
    <li><a href="index.php">Index</a></li>
    <li><a href="log.php">Log In</a></li>
</ul>

index.php

<?php 
    session_start();
    include("menu.php");

    echo "<br>Main page here<br>";
?>

log.php

<?php
    include("menu.php");

    session_start();

    if (!isset($_SESSION['user'])){
        $_SESSION['user'] = "Test Login";
        echo "Welcome " . $_SESSION['user'];
    }

    else {
        echo "You are already logged in as: " . $_SESSION['user'];
    }
 ?>

My issue is that every time I click the link to log.php using menu.php I always get the "Welcome Test Login" message, as if the session was resetting every click.

Is there a way to get the "You are already logged in as: Test Login" message from the second click on log.php onwards?

Laura
  • 83
  • 7

0 Answers0