include files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

include files

Post by JKM »

Hi there,

I have a folder called includes/, and I was wondering what the best way to block viewers to access/view the files in the include folder.
Everyone should be able to see: index.php?page=videos (where includes/videos.php is being included)
No one should be able to see includes/videos.php

I'm sorry if it's hard to understand my explanation :p
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: include files

Post by twinedev »

For best results, if you are using Apache, disable viewing indexes of Directories.

For just one directory though, you can put a blank index.html file in that directory.

Then, in case they somehow know the names of the .php files, since they are all designed to be included by another PHP script, check for a constant to be defined by the main program (index.php):

Code: Select all

define('SYSTEM_BASE',TRUE);
Then, at the top of every file that is included, and not meant to be called by itself, do the following:

Code: Select all

if (!defined('SYSTEM_BASE')) die ('Invalid direct call to file');
-Greg
Last edited by twinedev on Tue Sep 28, 2010 7:25 pm, edited 1 time in total.
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: include files

Post by JKM »

Nice, I tried the define() snippet, and it works great - thanks! :)
Post Reply