I want to assign a value to a session variable when a user logs into a website. I read that I must explicitly start a session at the top of my pages in order to do this. So I inserted:
if (!isset($_SESSION)){
session_start();
echo "started";
}
The first thing I notice is that "started" is displayed every time I reload my page. Is that expected behavior? I would assume the second time I load the page, the session should already be there, therefore "started" would not display.
Further down in my page, I have:
$_SESSION['id']=2;
echo "<p>Your session ID is: " . $_SESSION['id'] . "</p>";
That correctly displays the ID in the "echo" statement. So even after assigning a value to a session variable, when I reload the page, it puts "started" at the top.
Am I doing something wrong? Thank you!