Forum Moderators: coopster
if (ereg('[/\\]' . trim($_SERVER[PHP_SELF], '/') . "$", __FILE__)) die('This file can not be accessed directly!');
I have tested it and it seems to work. Is there some reason that this would not work? It just seems so easy that the !defined() method would not be so popular.
# path to include directory above web root
define('INCLUDE_DIR', '/path/to/includes/');
And then when you use it in your code it would always look like this:
require('config.php');
include(INCLUDE_DIR . 'file.php');
As far as answering your question, however, what you have at quick glance looks OK but I would go with the other option if I were you.