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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:16:19+00:00 2026-05-26T02:16:19+00:00

I have the same question but…I’m redirecting the user depending on an if statement

  • 0

I have the same question but…I’m redirecting the user depending on an if statement using headers to a dynamic page that is constructed through a function. For that function to work properly, it needs the parameters passed in the GET portion of the headers.

According to what to the answers provided, this is a bad practice. What way should I be doing it?

function page($title,$msg){
    $title = $_GET['title'];
    $msg = $_GET['msg'];
    echo '<h1>'.$title.'</h1>';

    echo '<p>';
    switch($msg){
        case 1:
            echo 'dwasdwadawdwadwa';
        break;
        case 2:
            echo 'wasdadwadwdad';
        break;
        default:
            echo 'wadasdasd';
        break;
    }
    echo '</p>';
}

ps: feel free to point out anything else you see wrong.

I found this but it doesn’t really help me.

  • 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-26T02:16:20+00:00Added an answer on May 26, 2026 at 2:16 am

    The answer to the question you linked suggests that functions should not rely on any external (e.g. global) variables. $_GET and $_POST (amongst others) are ‘super globals’, a language feature of PHP that makes them available in any scope. This means they may be unexpectedly modified from anywhere in your scripts.

    One way to help avoid this is to avoid using super globals in methods and instead – as the answer to the other question suggests – is to instead require parameters for the variables you would otherwise get from the super globals.

    E.g., instead of:

    function add_user() {
      $user = $_GET['user'];
      // ...
    }
    add_user();
    

    You would use:

    function add_user($user) {
      // ...
    }
    add_user($_GET['user']);
    

    In your situation, what you would want is:

    function page($title, $msg){
      echo '<h1>'.$title.'</h1>';
      echo '<p>';
      switch($msg){
        case 1:
          echo 'dwasdwadawdwadwa';
        break;
        case 2:
          echo 'wasdadwadwdad';
        break;
        default:
          echo 'wadasdasd';
        break;
      }
      echo '</p>';
    }
    

    Then, when you call page you would call it as:

    page($_GET['title'], $_GET['msg']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know many have asked the same question but I am still confused that
I have the same question as #1895500 , but with PostgreSQL not MySQL. How
I have an ObjectDataSource (but perhaps this question is the same for all kinds
I have basically the same problem outlined in this question, however I am using
vb.net windows forms question. I've got 3 forms that have exactly the same functions,
May be it's the same question i have i asked before but the issue
I have the same question that was asked in another post except I'm having
I hate to ask the same question others have asked in Stackoverflow, but I
I asked the almost the same question before also, but i have not yet
I am using Subversive and I have the same question as Subclipse svn:ignore ,

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.