Access php file outside root directory using jquery ajax request

I read a good practice for storing php files containing a potential security risk outside the root directory.

Now I have php files containing material for registration / login. They are located outside the root directory. Now I will catch the contents of the form via jquery and submit it to this php file.

But this is not possible with js / jquery:

$.ajax({
    type: "POST",
    url: "../php_includes/register.inc.php", //beyond root path
    data: data,
    })
    .done(function(data, status) {
            //...
    });

Am I having a design error or is something wrong?

What is the "best practice" here?

+4
source share
3 answers

(.. Javascript). , .

.

+3

" " 1. , index.php, login.php register.php, handler.php, ( ).

handler.php , . , .

-, handler.php. handler.php , :

<?php
include(__DIR__ . "/../includes/bootstrap.php");

:

RewriteEngine on
RewriteRule ^(.*)$ handler.php?path=$1 [QSA]
+7

You prefer to store security-related things, such as configuration files, and similarly in an external (not accessible) directory. But if you need to access the information stored in these files, you need to create a controller that will filter access and provide information in a safe manner, if necessary.

Apache will not serve files that are not in the root directory of the website.

+2
source

All Articles