Fri, 17 May 2024


How to ensure that a PHP file can not be executed directly but just included?

By: Peter, NetArt Media
Sat, 8 January 2022

This technique could be useful if you have some files to be included, and you wish to prevent that they are executed directly by placing their address in the web browser etc.

You need to add the following lines at the begining of your PHP script:

<?php
if ($_SERVER['REQUEST_URI'] == $_SERVER['PHP_SELF'])
die("A message ...");

...

?>


Category: PHP Examples
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox