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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:23:20+00:00 2026-06-08T04:23:20+00:00

So I’m wondering if the code (see below) is what could be called good

  • 0

So I’m wondering if the code (see below) is what could be called “good php code”. Its used where i work and i am trying to come up with a better solution to write this template.

The $requestedPage variable is used twice, first in the if and after that in the switch statement i don’t know why but i think there should be a better possibility.

The content is loaded through the require_once statement which will load the page content surrounded by the head.php and foot.php that contains the html – template.

<?php
    header("Content-Type: text/html; charset=utf-8");
    filter_var_array($_POST, FILTER_SANITIZE_STRING);


    require_once 'lib/rb.php';

    require_once 'head.php';


    $requestedPage = $_POST['page'];

    if(isset($requestedPage)) {
        switch ($requestedPage) {
            case 'list':
                require_once 'page/list.php';
                break;
            default:
                require_once 'page/home.php';
                break;
        }
    } else {
        require_once 'page/home.php';
    }

    require_once 'foot.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-08T04:23:23+00:00Added an answer on June 8, 2026 at 4:23 am

    You can remove the checking done twice. If the parameter is not set, it automatically goes into the default case of your switch statement.

    So, your code can be

    $requestedPage = $_POST['page'];
    switch ($requestedPage) {
            case 'list':
                require_once 'page/list.php';
                break;
            default:
                require_once 'page/home.php';
                break;
    }
    require_once 'foot.php';
    

    Edit: As @mario suggested in the comments, suppressing E_NOTICE which is shown when executing $requestedPage = $_POST['page']; can prove problematic in future, when there is a relevant notice and you have suppressed it. So, you should either suppress notices ONLY in production code, or check if $_POST['page'] is set before accessing its value, in the statement

    $requestedPage = $_POST['page'];

    • 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'm trying to select an H1 element which is the second-child in its group
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.