如何让用户无法访问PHP?

I´m using a lot of including while coding pages to keep the code a little bit more beutiful and avoid typing code multiple times.

example of index.php:

<?php 
include 'header.php';
?>

<p> random HTML </p> 

<?php
    include 'foo.php';
?>

The 'problem' now is that clients are able to navigate to www.page.de/foo.php and see this content. Is there a PHP-way to solve this without playing on .htaccess?

Don't place php files you don't want users to see in the public/ directory.

Edited out mention of .htaccess since you edited that into your question specification