spacer
Web Development Tutorials PHP Tutorials
 Developer Newsletter

Tutorials
AJAX
ASP
CGI & Perl
CSS
Flash
HTML
Illustrator
Java
JavaScript
Linux
MySQL
PHP
Photoshop
Python
Wireless
XML
Miscellaneous


Scripts Directory
AJAX Scripts
ASP Scripts
ASP.NET Scripts
CGI & Perl Scripts
Flash Scripts
Java Scripts
JavaScript Scripts
PHP Scripts
Python Scripts
Remotely Hosted Scripts
Tools & Utilities Scripts
XML Scripts

Web Hosting Directory
ASP.NET
Budget
Dedicated Servers
Ecommerce
Linux
Resellers
Shared
Small Business
Windows

Developer Manuals
Learn HTML
Learn PHP
Learn CSS
Learn JavaScript
Learn Pear
Free White Papers

Developer Resources
Developer Tools
Developer Content
Survey Software
Dedicated Servers




Using Define to Protect Files

By Joe S
2005-08-16


Using define to protect files in PHP

In my other tutorial I showed you how to include files dynamically using PHP [like main.php?x=whatever]
The files that you include can be accessed by anyone, which you may not want done.

Let's look at the code: ############
# Main file:
############
<?php
define
("MAIN", "True");
?>
# ############################
# Files that will be included:
# ############################
<?php
if(!defined("MAIN")){
die(
'<tt>You cannot view this file directly!</tt>');
}
?>

The first part, you put in the file that includes the rest of the files.
You can change MAIN and True to whatever yout want, just make sure to change it in the second part too.

Now we have to make the include files check if 'MAIN' (or whatever you changed it to) is defined.
We do that by putting the second part of the code at the top of every include file.
This will disallow direct viewing of any of the include files.



Tutorial Pages:
» Using define to protect files in PHP


© 2005 Joey Shamah


 | Bookmark Print |   Write For Us
Related Tutorials:
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1
» Desktop Application Development with PHP-GTK
» Installing PHP on Windows



About the NetVisits, Inc Network | Write For Us | Advertise
Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy.
Visit other NetVisits, Inc. sites: