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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:20:00+00:00 2026-06-16T23:20:00+00:00

Every single request is passed to PHP, for security reasons and because I don’t

  • 0

Every single request is passed to PHP, for security reasons and because I don’t want to expose static files to unauthorized people.

I am concerned about the possibility of someone inject some malicious code through the $_SERVER["REQUEST_URI"] variable. I tried to remove sub-folders references but I still don’t know if it’s safe.

Nginx

rewrite ^ /index.php last;

index.php

<?php
    $uri = $_SERVER["REQUEST_URI"];
    $uri = strlen ($uri) > 1 ? substr ($uri, 1) : "index.html";
    $uri = preg_replace ("/\/?\.\./", "", $uri, -1); // Remove sub-folders

    if (file_exists (getcwd () . "/" . $uri)) {
        $extension = substr ($uri, strrpos ($uri, "."));

        switch ($extension) {
            case ".css": $mime = "text/css"; break;
            case ".js": $mime = "application/javascript"; break;
            default:
                $info = finfo_open (FILEINFO_MIME_TYPE);

                $mime = finfo_file ($info, $uri);

                finfo_close ($info);
            break;
        }

        if ($mime === false)
            header ("Content-Type: text/html; charset=utf-8"); // Default
        else
            header ("Content-type: " . $mime);

        require ($uri);
    }
    else {
        // Error, blah blah blah
    }
?>
  • 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-16T23:20:01+00:00Added an answer on June 16, 2026 at 11:20 pm

    Yes, you are concerned about LFI (Local File Inclusion) attacks. It’s possible.
    Currently when you are checking for . / and \ chars in URI, that would prevent Directory Traversal attack. It’s fairly good.
    As you guessed, if you include files like this:

    index.php?file=something.php
    and in index.php
    include $_GET[‘file’];

    Attacker could read every file in your server, like this:
    index.php?file=../../../../../../../../../../etc/passwd

    So you have to take measures.
    Here is a very good writing from Imperva on how to prevent LFI and RFI (Remote File Inclusion) attacks:
    https://www.imperva.com/lg/lgw.asp?pid=463

    without registration requirement:
    http://www.slideshare.net/Imperva/how-to-prevent-rfi-and-lfi-attacks

    Also Here:
    http://25yearsofprogramming.com/blog/2011/20110124.htm

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

Sidebar

Related Questions

Basically, I want to inject some data into ViewData/ViewBag for every single request.
I want to store every single character of a string value in every single
Why do Android xml layout files need android: before every single view attribute? Doesn't
I tried using arrays but I don't need every single element, and so it
I have a PHP application that for every request loads 1 ini file, and
I'm doing some tracing in NewRelic, and I'm seeing almost every single request contains
I think I read every single web page relating to this problem but I
I have read nearly every single post about the activity not found to handle
I have an application where every single page uses a set of data that
I've been trying to follow every single tutorial and thread there is, i jast

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.