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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:18:33+00:00 2026-06-04T06:18:33+00:00

This is a dodgy question… When requesting a page, the output of the page

  • 0

This is a dodgy question…

When requesting a page, the output of the page depends on the parameters passed. Soo:

http://localhost/test/php?key=value

AND

http://localhost/test/php?key=other_value

will produce different outputs.

There are a lot of these parameters and sometimes they are set, sometimes they are not.

I have this code block, that I keep copying over and over:

if ( !isset( $PARAMS["type"] ) ){
    $message = urlencode("No Type Parameter Defined In File {$_SERVER["PHP_SELF"]}");
    header( "Location: /admin/pages/{$PARAMS["page"]}?m=$message" );
    exit;
}

Now this code block is repeated in some cases about 6 times!

So I thought I could write a function:

function redirect_on_fail( $var ){
    if ( !isset( $var ) ){
        $message = urlencode("No Type Parameter Defined In File {$_SERVER["PHP_SELF"]}");
        header( "Location: /admin/pages/index?m=$message" );
        exit;
    }
}

OBVIOUSLY this will not work

Because I will have to call redirect_on_fail( $PARAMS["type"] ); and if it is not set, it wont be passed to the function…

Because I need to test whether the variable exists in the Pages Scope…

So I could just do this, I suppose:

function redirect_on_fail( $message, $redirect_to ){
    header( "Location: /admin/pages/$redirect_to?m=".urlencode($message) );
    exit;
}

But then in the page I’m doing:

if ( !isset( $PARAMS["type"] ) ){
    redirect_on_fail( "No Type Parameter", $redirect_to );
}

and that defeats the point…

So is there a way around this?

  • 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-04T06:18:34+00:00Added an answer on June 4, 2026 at 6:18 am
    function redirect_on_fail () {
      $args = func_get_args();
      $params = array_shift($args);
      foreach ($args as $arg) {
        if (!isset($params[$arg])) {
          $message = urlencode("No $arg Parameter Defined In File {$_SERVER['PHP_SELF']}");
          header("Location: /admin/pages/index?m=$message");
          exit;
        }
      }
    }
    
    // Call it like:
    redirect_on_fail($_GET, 'required_key', `another_required_key`);
    // Basically takes an array as the first argument, then the required keys as
    // subsequent arguments, and redirects the user if any of them are not set.
    // Pass as many required key names as you like.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having just written the title for this question I am aware of how dodgy
this is my first question in here, and I would like to ask if
This question is directly related to this SO question I posed about 15 minutes
This question is kind of a follow up to this question I asked a
I wrote this small game at http://amarnus.me/games/dodge . Now if you trying playing the
I saw this page growing in popularity among my social circles on Facebook, what
Dodgy - Write to static field from instance method This is the line it
Background This question is in two parts. I have a one-way WCF operation hosted
I'd like to add spaces between bars in ggplot2. This page offers one solution:
This question is related to Does this C++ static analysis rule make sense as

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.