PhpSnip.com

User Stats

protect php include file

This is describe how we can protect php include file unser directory that not protected, this is simply done using php function

Info

 Download  View Source (print view)
 Rating : 4.7  Views : 583

Source Code ( 45 lines )

<?php
/* syntax
   adding this line on top your script code
   before outpur anything
   to prevent this file when not include

  sytax 1 :

  if(!eregi("THIS_FILE_NAME",implode(";",get_included_files()))){ exit;}

 THIS_FILE_NAME= replace with the include 
 file name you want to protect 
{must be this file  name valid}

 note: do not use $PHP_SELF for above 
 script because it does not same with
 this_file_name when its include

syntax 2:
 
 alternative script using $PHP_SELF is :

 if($PHP_SELF!="main_file_name") exit;
 
 you can replace main_file_name with
 file that will calling this include file but
 it is not efective when multiple file
 want to calling this file in include function

 I suggest using syntax 1 is the best

 
*/


//example if this filename is config.php
//include handler
if(!eregi("config.php",implode(";",get_included_files()))){ exit;}


///your code goes here
//..................
//.................

?>

Search

Subscribe

  Rss Feeds

Sponsors

Advertise