PHP restrictions include ()

Hi guys, I separate XHTML from PHP by putting XHTML in a separate file and then using the PHP include()function in a PHP script.

This works fine, but users can still access the file .htmldirectly if they know the address. They can't really handle this much, but I would prefer it not to show.

I saw some scenarios in the past use some form of referrer check, is that what I would do to add some basic (note that I said "basic") restrictions to prevent it from being viewed by directly accessing it?

Thank!

Explanation . I forgot to mention that I want to do this in PHP, so there is no web server configuration (moving files from the root directory, setting the web server to deny access, etc.).). I think that the most logical choice here is to use a constant check define(), which is really what I saw in other scenarios that I forgot, as I stated in my post. I understand that this is probably not the best solution, but given that the html file that may be available does not really matter, the constant define()should be sufficient. Thank you, I appreciate the answers!

+3
source share
6 answers

(, index.php) /something/public_html/, /something/. , .

/public_html/ . example.com, . , -, .

, include, .

- - ,

if(!defined("RUNNING_SCRIPT"))
    die("No Direct Access Allowed");

PHP

 define("RUNNING_SCRIPT", true);

RUNNING_SCRIPT , , , . , PHP .html.

.htaccess .

+3

. , PHP .

+3

-, ?

+3

, - :

index.php:

<?php

define('ALLOW_INCLUDE', true);

include('other.php');

?>

other.php:

<?php

if (defined('ALLOW_INCLUDE') === false) die('no direct access!');

// your code

?>
+3

.

.htaccess index.html .

<?php defined('SOME_CONSTANT_GLOBAL_TO_YOUR_APP') or die('Access denied.'); ?>
+1

Source: https://habr.com/ru/post/1728565/


All Articles