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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:23:45+00:00 2026-05-25T01:23:45+00:00

All, I’m building a front controller in PHP. In it, I say: if (isset($_GET[‘action’])){

  • 0

All,

I’m building a front controller in PHP. In it, I say:

if (isset($_GET['action'])){
        $action=$_GET['action'];
    } else {
        $action='';
    }

I follow that with a switch statement than governs which controller is called based on the value of $action:

switch ($action){
        case '':
            require_once('Controller_Welcome.php');
            $command=new controller_Welcome();
            break;
        case 'logon':
            require_once('Controller_Logon.php');
            $command=new controller_Logon();
            break;
        default:
            require_once('Controller_Unknown.php');
            $command=new controller_Unknown();
            break;
    }
$command->execute();

This works fine. When I launch the app, the URL is http://.../Index.php? and the Controller_Welcome.php is called. If I click on the logon menu entry, I get http://.../Index.php?action=logon, and the Controller_Logon.php is called. If I manually edit the URL to set ...?action=... to some unknown value, I get Controller_Unknown.php, which is my error page. So all is well.

What I don’t understand is that if I manually alter the url to show http://.../Index.php?action=, I get the error page rather than the welcome page. Why is it that php doesn’t associate a url ending with ...?action= with the switch case $action='';?

(There’s no logical user case when that would happen, but I still don’t understand it…)

Thanks,

JDelage

PS: Var_dumping $action returns string(0) "".

  • 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-25T01:23:46+00:00Added an answer on May 25, 2026 at 1:23 am

    When you set ?action=, you will get a null return value for $_GET['action']. So in your scenario, the switch statement will use the default case. Like everyone said, you can always use var_dump to see the return value.

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

Sidebar

Related Questions

All the guys probably will recommend that I read the follow previously question in
All the code/commands below are part of a PHP script that processes images from
All of a sudden my form link looks like this: <form action=/r.ashx/Models.Module_ContactUs?action=Submit&amp;controller=Contact id=contactUsForm method=post>
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
All, I am building a small site using PHP. In the site, I receive
All front-end developers know the pain of coding for Firefox, then viewing our then
All too often I want a WPF slider that behaves like the System.Windows.Forms.TrackBar of
All, I currently have two projects that are under SourceSafe that I am unable
All, I have some script tags that are not working in Wordpress. If I
All programs that I develop utilize the default Windows Design template: Besides from changing

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.