PHP cannot read files containing PHP code as text files

I came across the following feature:

$ handle = fopen (realpath ("../folder/files.php"), "r");

cannot read the file, but as soon as I remove the php tags from the file, it becomes readable, and my scripts print non-empty content on the page. Also, file.php is never executed, so I wonder why this is a problem.

I assume that Apache or PHP does not allow reading files containing PHP PHP tags as text.

How can I include it for my specific file (a course doing it globally would be unsafe)?

Using PHP 5.2.x and Apache 2.0

+3
source share
6

. Google chrome , , Chrome - PHP-. Firefox, , .

:

:

$fh = fopen("test.php","r");
while ($line = fgets($fh)){
echo $line;
}

(test.php):

testing <?php testing2 ?> testing3

( Chrome, firefox):

testing  testing3

( firefox):

testing <?php testing2 ?> testing3

( Chrome - ):

testing  testing3
+11

, ? , , . text/plain " " , , , , , .

+7

Hmm file_get_contents() . fopen?

: ?

0

. . PHP php , , View Source . !

0

htmlspecialchars($line);

.

0

rerename :)

-1

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


All Articles