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

  • Home
  • SEARCH
  • 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 9079015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:45:07+00:00 2026-06-16T19:45:07+00:00

I keep getting undefiendd variable for steps in Text5.php when accessing Text2.php . My

  • 0

I keep getting undefiendd variable for steps in Text5.php when accessing Text2.php. My question is how come I amgetting an undefined variable as I have included the variable $steps as an array:

Text5.php

    <?php

$steps = array(1 =>'Text1.php',2 => 'Text2.php',3 => 'Text3.php',4 => 'Text4.php',5 => 'Text6.php',6 => 'Text7.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;
}

?>

Text2.php

            if (allowed_in()=== "Allowed")
    {
        //Text2.php code
    }
    else
        {
$page = allowed_in()+1;
?>

<div class="boxed">
<a href="<?php echo $steps[$page] ?>">Link to Another Page</a>
</div>

<?php   

}

?>
  • 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-16T19:45:08+00:00Added an answer on June 16, 2026 at 7:45 pm

    My question is how come I amgetting an undefined variable as I have included the variable $steps as an array

    You never actually called allowed_in with any array.

    Both if (allowed_in()=== "Allowed") and $page = allowed_in()+1; calls the allowed_in() function without any parameters, and in your function:

    function allowed_in($steps){ you specify that there MUST be a variable (that we create name $steps).

    You can create default parameters by using the = sign:

    function allowed_in($steps = array()){
        //Logic
    }
    

    Which means you can now call it with no parameters.

    You might also be looking for global in case it’s because your $steps variable is in the global scope:

    function allowed_in(){
        global $steps;
        //Logic
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code and I keep getting undefined if I test the selectedIndex.
I keep getting undefined as result from returning the variable inside a function. This
I keep getting an 'Undefined variable' notice when I call on an object I
I keep getting an Notice: Undefined index: did error with this query, and I'm
I keep getting this error and have no idea why. I googled and scanned
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I am just learning
as the title says, I keep getting undefined when I try to get the
I keep getting Undefined Index for the following: $username = $_POST['username']; $email = $_POST['email'];
Possible Duplicate: PHP: Notice: Undefined variable and Notice: Undefined index I am new to
Possible Duplicate: Undefined variable problem with PHP function Can someone tell me why I

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.