php - Checking a constant for security reason -


some applications use code first line on every page included index.php:

if (!defined('secure_const')) { die("access denied!"); } 

why need use this? necessary security? if yes, how can use properly?

it's done ensure files not executed directly. example:

/index.php

<?php   define('secure_const', 1);   include 'include_me.php'; ?> 

/include_me.php

<?php   if (!defined('secure_const')) { die("access denied!"); } ?> 

then, if http://example.com/index.php requested secure_const defined , die() not invoked when include_me.php included. however, if http://example.com/include_me.php requested directly, secure_const never defined , script bails.

if web server configured securely--i.e. files not intended accessed directly outside web root or in directory made inaccessible e.g. .htaccess--this should unnecessary. developers use "security" measures because assume, rightly, many people using software not take time understand security issues , configure servers properly, , use methods failsafe.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -