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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:07:24+00:00 2026-05-26T10:07:24+00:00

I have a simple (excercise) website whose structure consist of a content selection menu

  • 0

I have a simple (excercise) website whose structure consist of a content selection menu and a content panel, where content is displayed when one the elements of the menu is selected.
The menu use links of the type ?content_id=... to pass the information over.

I would like to handle 404 codes on inexistent ids or missing contents but to do so I have to compute the content of the content panel befor the page loads, so that I can output the correct header before everything else. I ended up writing this piece of code at the beginning of my file and printing the $content variable when necessary. Anyway, I feel quiet uncomfortable with this approach since I have to stop the natural flow to catch the include output.

<?php 
  // if no content is specified in the address, select the home page (0)
  $content_id = (isset($_GET['content_id'])) ? $_GET['content_id'] : 0;

  //check if selected content exists and put the content inside the $content variable (to be used later)
  if ($content_id < 0 OR $content_id > 2 OR !is_file('exContent/content'.$content_id.'.php')) {
    header("HTTP/1.0 404 Not Found");
    ob_start();
    include 'exContent/noContent.php';
  }
  else { 
    ob_start();
    include 'exContent/content'.$content_id.'.php';
  }

  $content = ob_get_contents(); ob_end_clean();
?>

I cannot figure out what’s the best way to do this, I would be very happy if you can 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-26T10:07:25+00:00Added an answer on May 26, 2026 at 10:07 am

    Could be a lot better but this is a start 🙂

      $includeFile 'exContent/content'.$content_id.'.php';
    
      if ($content_id < 0 OR $content_id > 2 OR !is_file( $includeFile )) {
        header("HTTP/1.0 404 Not Found");
        $includeFile = 'exContent/noContent.php';
      }
    
      ob_start()
      include $includeFile;
      $content = ob_get_contents();
      ob_end_clean();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the simple question, but i have an excercise where I have to
I have a list of about 200 integers whose values are between 1 and
I have a simple grammar consisting of mixed variables ( $(name) ) and variable-value
I have a simple address book app that I want to make searchable. The
I have a fairly simple console app that monitors an exchange mailbox, picks particular
I have a simple code: NSMutableArray *arrayCheckList = [[NSMutableArray alloc] init]; [arrayCheckList addObject:[NSMutableDictionary dictionaryWithObjects:[NSArray
I'm having a strange behavior in Linq to Sql... I have a simple parent
As a practice exercise at my college we have to make a simple room
I have what I think is a simple solr exercise, but I'm unsure what
I am new to Objective-C and as a very simple learning exercise, I have

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.