Wednesday 12 October 2011

Make script not directly accessible

So if you're a PHP developer and want to make some include files protected. Basically so no one can look directly at them for whatever reason, simply;

<?php
if(preg_match("/".basename(__FILE__)."/i",$_SERVER['REQUEST_URI']))
{
 die("Direct access is not allowed");
}
?>

Simples!

No comments:

Post a Comment