I am working on a site where each page requires a user to be logged into the system. The whole site relies on HTML template files that are included in the pages. However, if a user knew the name of a template file, they could browse to that page by entering the url... as the template file does not require a log in.
Is it possible to make template files that can only be included and not viewed by themselves? Then, if a user browses only to the template file, they are redirected, or get an error?
I tried something like this at the top of the template files:
<? if ($_SERVER["SCRIPT_NAME"] != $_SERVER["PHP_SELF"]) { ?>
but that doesn't work because if the file is included, then the script name and php self are the same.
At the top of every non-template page, I call these functions to require a log in:
require_login();
require_priv("admin");
I tried putting this at the top of the template page, but that doesn't work either because these functions are in another functions file that is not included in the template because it can't be called twice on the same page.
I want my files to be include-only. They can be called by other files on the server, but cannot be called by a user.
Any one creative enough to come up with a good solution for this?