0

I am using a common file called menubar.php which obviously shows menubar. I am using REQUIRE("menubar.php") in all the files which need menubar to be shown. The problem I am facing is I don't want the menubar to be displayed if I am accessing it through url ex. localhost/project/menubar.php.

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46

1 Answers1

0

That is how I prevented direct access from URL to your menubar.php file. Paste the following code in .htaccess file inside the directory where 'menubar.php' file is located.

<Files ~ "menubar.php">
  Order allow,deny
  Deny from all
</Files>

It will prevent to access menubar.php file via url, but it can access inside your server language.

Jino Shaji
  • 1,097
  • 14
  • 27
  • There is no guarantee this is an Apache type server, or that the server config will allow this. – Brian Gottier Sep 10 '17 at 06:08
  • 1
    thanks for the suggestion jino shaji. What I did instead was used session. In menubar.php i am using a session variable but I did not write session_start(). I write session_start where i need the menubar then require 'menubar.php'. This way the menubar.php only executes when it was called by a php page having session_start() – Piyush Patil Sep 10 '17 at 10:40