Recent Posts

This Post Has Been Viewed 322 Times.

How to avoid direct access to a file in php

Posted by admin | Posted in PHP, scripts | Posted on 05-08-2009

0

If you don’t want users to access some files directly from browser then you can simply use following php script on top of such files.

Let us take one file named MYFILE.PHP as an example, all you have to do is just add the below code on the top of  all the script

<?php

// this is first code block

if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME']))

{

// tell people trying to access this file directly goodbye…

exit(”This file is restricted from direct access”);

}

//Rest of the code in your file comes after this

?>

Hope this one will help.Thanks.

TitleVotesRatingReview
VN:F [1.5.7_846]
Rating: 5.0/10 (1 vote cast)
VN:F [1.5.7_846]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • De.lirio.us
  • Xerpi

Related posts:

  1. Loading swf file from another server using crossdomain.xml
  2. Recuva best file recovery software

Write a comment

Spam Protected