I am trying to make simple navigation rules for a visitor for my website. I want to prevent visitor accessing specific pages if they have not visited other pages before. I have this simple code on page1.php:
<?php
session_start();
$_SESSION["currentPage"] = 1;
?>
And this code on my page2.php:
<?php
session_start();
if ($_SESSION["currentPage"] == 1 ) {
$_SESSION["currentPage"] = 2;
$_SESSION["test"] = "Hello";
}else{
$_SESSION["currentPage"] = 3;
}
?>
After visiting page1.php and then page2.php and echoing out $_SESSION["currentPage"]
and $_SESSION["test"]
I get "Hello
" and "3
".
I just don't understand why the code is executed in both blocks of the if statement...I need it to stop after $_SESSION["currentPage"]
is set to "2
".
I am running PHP 5.3.28