Facebook Twitter Reset

This Tutorial Has Been Viewed 1,361 Times.

How to avoid direct access to a file in php


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.

VN:F [1.9.13_1145]
Rating: 4.4/10 (5 votes cast)
VN:F [1.9.13_1145]
Rating: -2 (from 2 votes)
How to avoid direct access to a file in php, 4.4 out of 10 based on 5 ratings

Incoming search terms:




You will also be interested in ,

No comments yet.

Leave a Comment

Spam protection by WP Captcha-Free

Affordable Seo PackagesSeo BlogEdu Backlinks
More in Css, scripts (59 of 94 articles)