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 7630815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:11:46+00:00 2026-05-31T06:11:46+00:00

I’m new to php and need some help with GET variables. Here an extraction

  • 0

I’m new to php and need some help with “GET” variables.

Here an extraction of my Code for index.php:

$array = array("section","view","sub","cat","point");
$i = 0;
$check = true;

foreach ($_GET as $position => $wert) {
  if ($position != $array[$i]) {
    //if GET doesnt exist in the array set check to false
    $check = false;
    break;
  }
  $i++;
}

//if GET variables exists
if ($check == true) {
  if (isset($_GET['section'], $_GET['view'], $_GET['sub'], $_GET['cat'], $_GET['point'], $point[$_GET['point']])) {
    $path = $path_dynamic.$_GET['section']."/".$_GET['view']."/".$_GET['sub']."/".$_GET['cat']."/".$point[$_GET['point']];
    check($path);
  } else if (isset($_GET['section'], $_GET['view'], $_GET['sub'], $_GET['cat'], $cat[$_GET['cat']])) {
    $path = $path_dynamic.$_GET['section']."/".$_GET['view']."/".$_GET['sub']."/".$cat[$_GET['cat']];
    check($path);
  } else if (isset($_GET['section'], $_GET['view'], $_GET['sub'], $sub[$_GET['sub']])) {
    $path = $path_dynamic.$_GET['section']."/".$_GET['view']."/".$sub[$_GET['sub']];
    check($path);
  } else if (isset($_GET['section'], $_GET['view'], $view[$_GET['view']])) {
    $path = $path_dynamic.$_GET['section']."/".$view[$_GET['view']];
    check($path);
  } else if (isset($_GET['section'], $section[$_GET['section']])) {
    $path = $path_dynamic.$section[$_GET['section']];
    check($path);
    //if section isn't set
  } else if (!isset($_GET['section'])) {
    include ($path_dynamic.$section['news']);
  }
} else {
  echo "GET doesn't exist";
  include ($path_static.$section['error']);
}

//check if GET exists
function check($path) {
  if (file_exists($path)) {
    echo "File imported<br />";
    include ($path);
  } else {
    echo "GET set correct but file doens't exist";
    include ('include/static/fehler.html');
  }
}

Example of section.php (view, sub, cat and point is the same):

$section = array();
$section['error'] = 'fehler.html';

My problem is that if i set this link:

index.php?section=verein&view=vorstande

“vorstande” doesn’t exist in my view array. So the code checks for the section “verein” and include “verein”. But it should give an error.

So it seems that this code

 } else if (isset($_GET['section'], $_GET['view'], $view[$_GET['view']])) {

is ignored and it jumps to

  } else if (isset($_GET['section'], $section[$_GET['section']])) {

Also if I change my url to this:

index.php?section=vereine&view=vorstande

nothing happens. I even don’t know where the code is right now.

But if I change the url to this:

index.php?section=vereine&view=vorstand

everything works fine.

So “verein” and “vorstand” is defined by me. “vereine” and “vorstande” doens’t exist.

Any suggestions? Sry for comments in german. The echo only gives me a hint where the code is right now!

Link to my HP:

Edit:
– translated comments for better conversation
– deleted all “$…[$_GET[‘…’]]” structures to show the error I will get instead.

  • 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-05-31T06:11:47+00:00Added an answer on May 31, 2026 at 6:11 am

    “vorstande” doesn’t exist in my view array. So the code checks for the
    section “verein” and include “verein”. But it should give an error.

    By “give an error” you mean $check = false;?

    } else if (isset($_GET['section'], $_GET['view'], $view[$_GET['view']])) {
    

    If in your $view the key vorstande does not exist, this the whole condition will evaluate to false and next condition will be checked:

    } else if (isset($_GET['section'], $section[$_GET['section']])) {
    

    Edit:

    Your code:

    else if (isset($_GET['section'], $_GET['view'], $view[$_GET['view']])) {
        $path = $path_dynamic.$_GET['section']."/".$view[$_GET['view']];
        check($path);
    }
    

    Your requirement:

    if (!isset($view[$_GET['view']]))
        check(/* something invalid to display fehler.html */ false);
    

    What actually happens:

    isset($_GET['section'])     // true
    isset($_GET['view'])        // true
    isset($view[$_GET['view']]) // FALSE
    
    => isset($_GET['section'], $_GET['view'], $view[$_GET['view']]) // FALSE
    

    If the $_GET['view'] does not exist in $view, the block which would call check is not executed. If you want it to be executed regardless, simply remove the condition isset($view[$_GET['view']]):

    else if (isset($_GET['section'], $_GET['view'])) {
        $path = $path_dynamic.$_GET['section']."/".@$view[$_GET['view']]; // @ to suppress errors from accessing 
        check($path);
    }
    

    If you don’t like this approach, work on your cases. You have one case for section isset AND view isset AND view is valid. The next case ignores the view parameter. So if your view parameter is not valid, your code handles it like it was not set. The requirement though is to have a case for section isset AND view isset AND view is invalid:

    else if (isset($_GET['section'], $_GET['view']) && !isset($view[$_GET['view']])) {
        check(false);
    }
    

    This is of course pretty much redundant checking so just nest it to something like:

    else if (isset($_GET['section'], $_GET['view']))
    {
         // section and view have been passed
    
         if (isset($view[$_GET['view']])
             // view is actually valid
             $path = $path_dynamic.$_GET['section']."/".$view[$_GET['view']];
    
         else
             // view has been passed but is invalid. show fehler.html
             $path = false;
    
         check($path);
    }
    

    Alternate Example

    If I understand you correctly, you have the following requirement: If the user passes a parameter section, view, sub, cat or point, you want that this value is also in your list of valid values. If it isn’t, you want to display fehler.html.

    We now first ensure that if the parameter is set, it is also valid:

    foreach ($array as $param)
    {
        // example for $param == "view":
        // !isset( $view[$_GET["view"]] )
        if (!isset( ${$param}[$_GET[$param]] ))
        {
            $check = false;
            break;
        }
    }
    

    We then check all your combinations of parameters and build a $path

    $path = false;
    if ($check)
    {
        // your long if isset else if isset block where 
        // isset($_GET['view']) also implies isset($view[$_GET['view']])
        // so you don't have to check for it.
    
        // just set the $path variable with some string.
        // we are going to check it later
    }
    

    If now the initial $check failed or we built an invalid $path, display fehler.html

    if ($check === false || !file_exists($path))
    {
        // display fehler.html
    }
    else
        include($path);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

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.