Thursday, October 24, 2013

Prevent direct access to a php include file

Prevent direct access to a php include file


This is the way to prevent direct access to a php include file on web host.

place following code on top of the base file:

like there is a form.php and you  need to include it on register.php (you need to write include('form.php') code on regidter.php file)

The Bas file is "register.php"

<?php

define('MyConst', TRUE);

?>

and you need to place following php code on top of the includable file (form.php) :

<?php

if(!defined('MyConst')) {

die('Direct access not permitted');

}
?>

1 comments: