Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9086911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:35:47+00:00 2026-06-16T21:35:47+00:00

I am trying to create something like a lock and unlock pages feature. The

  • 0

I am trying to create something like a lock and unlock pages feature. The user has to go thorugh the pages in this order:

$steps = array(1 =>'create_session.php',2 => 'QandATable.php',3 => 'individualmarks.php',4 => 'penalty.php',5 => 'penaltymarks',6 => 'complete.php');

So what should happen is that if the user is on a page a they SHOULD BE on, then that page shold be unlocked (or in other words the if statement is met where it shows the page’s code), if the user accesses a page which they should not be on, then that page beocmes locked (the else statement is met where it displays the div with the Continue hyperlink`).

The problem is that even though the user is on the correct page, the page is still “locked” when it should be unlocked so the user can use the page. At moment all pages accessed are locked so my question is that how can I unlock a page when the user is on a correct page?

Below is an example create_session.php:

 <?php
session_start();
include ('steps.php'); //exteranlised steps.php
?>
<head>
...

</head>
<body>

<?php
if ((isset($username)) && (isset($userid))) { //checks if user is logged in
    if (allowed_in() === "Allowed") {
        //create_session.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 = array()){
// 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;
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:35:48+00:00Added an answer on June 16, 2026 at 9:35 pm

    Keep it simple, seems that you are over complicating the goal. It seems like you simply want to ensure that the user completes previous steps of a process before they can continue on to the next. Why not try something more like…

    // General Idea
    $completedArr = array('1' => false, '2' => false ...);
    $pageMap = array('page1.php' => '1', 'page2.php' => '2' ...);
    
    // On Page1
    $completedArr = $_SESSION['completedArr'];
    $locked = true;
    $currentStep = $pageMap[$_SERVER['SCRIPT_NAME']];  // '1'
    if($currentStep > 1)
    {
        if($completedArr[$currentStep - 1] === true)
            $locked = false;
    }
    else
    {
        $locked = false;
    }
    
    $completedArr[$currentStep] = true;
    $_SESSION['completedArr'] = $completedArr;
    

    Use this as needed for continuous pages also. The idea is that the pageMap you would define to give index numbers to script names. Then you would simply check to see that the previous index was marked as completed before “unlocking” this page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an array which will follow something like this array(
I am trying to create a array that should be something like this: [
I am trying to create something like this as i have done it in
I'm trying to create something that works like this but doesn't have any submenus.
I'm trying to create a jQuery selector that will do something like this: (.a
My httpd-vhosts.conf file looks something like this. I am trying to create 2 virtual
I'm trying to create a animation by scrolling the page, something like this: $(function()
I am trying to create something like this: This example creates view using a
I am trying to create something like this (look at the time), you can
I'm trying to create a button which looks something like this: With each third

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.