below I have scenario of what SHOULD happen:
- User is on
create_session.phppage, so the other pages in the array are
locked out - If user tries to access another page they are displayed with the div
box shown above: - If user selects Continue link then it should navigate the user to the
page they should be on which wascreate.phppage
The problem is that if the user accesses another page and the div box appears, if user click on the Continue link, it does not navigate back to the create_session.php page or in other words the page the user was last on.
The url does not seem to change after clicking on the Continue Link
Why is it not navigating the user to the page they should be on after clicking on Continue?
The script that tries to control which pages are locked out and keeping the page the user is on unlocked is in this script steps.php which is shown below:
<?php
function allowed_in(){
$steps = array('create_session.php', 'QandATable.php', 'individualmarks.php', 'penalty.php', 'penaltymarks', 'complete.php');
// Track $latestStep in either a session variable
// $currentStep will be dependent upon the page you're on
if(isset($_SESSION['latestStep'])){
$latestStep = $_SESSION['latestStep'];
}
else{
$latestStep = "";
}
$currentStep = basename(__FILE__);
$currentIdx = array_search($currentStep, $steps);
$latestIdx = array_search($latestStep, $steps);
if ($currentIdx - $latestIdx > 1 ) {
return true;
} else {
return false;
}
}
?>
Now each script stored in the arrays contains the code include('steps.php') and contains the code below:
<?php
if (allowed_in()){
//create_session.php code
}else{
?>
<div class="boxed">
<a href="<?php echo $steps[$latestIdx + 1] ?>">Continue</a>
</div>
<?php
}
?>
UPDATE:
When I click on Continue link, in url it displayed two errors which were below:
notice: Undefined variable: latestIdx in … on line 1636
Notice: Undefined variable: steps in … on line 1636
Notices are displayed for this line below:
<a href="<?php echo $steps[$latestIdx + 1] ?>">Continue</a>
UPDATE 2:
When I navigate to a page which is locked (in other words when the box which states you have to Continue appears, I am getting undefined $_SESSION variables and I am also getting this error: Undefined variable: steps in steps.php on line 57
For the $_SESSION undefined errors, is it because I am placing the $_SESSION variables in the wrong place? And how can I stop the undefined variable of steps in steps.php?
Below is an example QandATable.php order of code looks like:
<?php
ini_set('session.gc_maxlifetime',12*60*60);
ini_set('session.gc_divisor', '1');
ini_set('session.gc_probability', '1');
ini_set('session.cookie_lifetime', '0');
require_once 'init.php';
//12 hours sessions
session_start();
include('steps.php'); //exteranlised steps.php
<head>
if (isset($_POST['id'])) {
$_SESSION['id'] = $_POST['id'];
}
if(isset($_POST['sessionNum'])){
//Declare my counter for the first time
$_SESSION['initial_count'] = $_POST['sessionNum'];
$_SESSION['sessionNum'] = intval($_POST['sessionNum']);
$_SESSION['sessionCount'] = 1;
}
elseif (isset($_POST['submitDetails']) && $_SESSION['sessionCount'] < $_SESSION['sessionNum']) {
$_SESSION['sessionCount']++;
}
</head>
<body>
<?php
//once session is expired, it should log the user out, but at mo this isn't happening
if ((isset($username)) && (isset($userid))){ //checks if user is logged in
if (allowed_in()=== "Allowed"){
//QandATable.php code:
}else{
$page = allowed_in()+1;
?>
<div class="boxed">
<a href="<?php echo $steps[$page] ?>">Continue with Current Assessment</a>
<?php
}
}else{
echo "Please Login to Access this Page | <a href='./teacherlogin.php'>Login</a>";
//show above echo if user is not logged in
}
?>
Below is the full steps.php:
<?php
$steps = array(1 =>'create_session.php',2 => 'QandATable.php',3 => 'individualmarks.php',4 => 'penalty.php',5 => 'penaltymarks',6 => 'complete.php');
function allowed_in($steps){
// Track $latestStep in either a session variable
// $currentStep will be dependent upon the page you're on
if(isset($_SESSION['latestStep'])){
$latestStep = $_SESSION['latestStep'];
}
else{
$latestStep = 0;
}
$currentStep = basename(__FILE__);
$currentIdx = array_search($currentStep, $steps);
$latestIdx = array_search($latestStep, $steps);
if ($currentIdx - $latestIdx == 1 )
{
$currentIdx = $_SESSION['latestStep'];
return 'Allowed';
}
return $latestIdx;
}
?>
This:
I think Should be this:
and not sure were this is coming from:
Your steps array will need to be declared outside of the function as well
You have to return $latestIdx if yo plan to use it in the url. I am not sure if you are trying to go back or forward?
Still not sure if i understand exactly what you want but this should be a start:
and Page