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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:18:38+00:00 2026-06-12T02:18:38+00:00

Ok, am using traditional php, no frameworks, nothing, I am using simple procedural way,

  • 0

Ok, am using traditional php, no frameworks, nothing, I am using simple procedural way, now my question is I was searching for a while but am not getting an answer to my question, I am not using .htaccess files as of now, but I really need to understand how 404 error works? I am having a website, where I show post’s related to category, say category=php, so I pass this as a get request

$_GET['category'] == 'php';

Now currently what am doing is something like this :

$pocategory = $_GET['category'];

if($pocategory == 'php' || $pocategory == 'javascript') {
//Then show related posts
} else {
header('Location:404.php');
exit;
}

I mean I just want php and javascript as valid request’s value, rest I want to redirect to 404 but am not understanding how to do it so I did this way, what if am having more than 50 categories? I cant list them all in this if condition, Inshort how to detect whether the given get request value is invalid or not..

Any help will be much appreciated.

  • 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-12T02:18:39+00:00Added an answer on June 12, 2026 at 2:18 am

    .htaccess is the way to do this.

    ErrorDocument 404 index.php?404
    

    that line will tell apache what file to load. The example above calls the main index.php script.

    add something like this to the top of your index.php file:

    $error_404 = isset($_GET["404"]) ? true : false;
    

    now you can detect if you have a 404 error request. $error_404 will be true, so why not add a simple function:

    function error_404($error_404)
    {
        if($error_404 == true)
        {
           // do some error stuff here, like set headers, and some text to tell your visitor
        }
    }
    

    now just call your function:

    error_404($error_404);
    

    best to do that immidiatley after the get handler:

    error_404($error_404)
    $error_404 = isset($_GET["404"]) ? true : false;
    

    or combine the two into one line:

    error_404($error_404 = isset($_GET["404"]) ? true : false);
    

    to address the question, add this to the relevant script:

    $pocategorys_ar = array("php","javascript"); 
    
    if (!in_array($pocategory, $pocategorys_ar)) 
    { 
        error_404(true); 
    } 
    

    Make sure it has access to the error_404() function.

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

Sidebar

Related Questions

How can we separate Logic from presentation without using any template engine (traditional php-not
Iam trying to implement a simple JMS(traditional not using springs) code in eclipse using
I'm using this php code for an image upload. But I keep getting an
I am using cURL via PHP to test service connections, and I'm getting some
I'm using git-svn to interact with a remote svn repsitory that follows the traditional
What do you think about the concept of using ORO instead of traditional Garbage
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using SQL Server 2008 R2 we are looking for a way to select the
locale_accept_from_http is a basic wrapper around ICU's API uloc_acceptLanguageFromHTTP but the PHP/PECL implementation seems
This might be a silly question but it struck me, and here i ask.

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.