0

I want to prevent direct access of my PHP pages. I tried running ".htaccess", but it is not running. There are so many pages in my project. but I want in some of them. My PHP pages are: example1.php example2.php

My ".htaccess" code is:

     Options +FollowSymlinks
     RewriteEngine on
     RewriteRule    ^/?example/([0-9]+)$    exam-ple.php    [NC,L]

If it is OK, then why it is not running. I want any type of solution.

Mohit
  • 57
  • 7
  • Put the files outside the web-root –  Mar 25 '16 at 05:00
  • Possible duplicate of [Prevent direct access to a php include file](http://stackoverflow.com/questions/409496/prevent-direct-access-to-a-php-include-file) – Harikrishnan Mar 25 '16 at 05:02
  • Deny From all. It denied access from everything. I want these pages should accessible only through hyperlinks. – Mohit Mar 25 '16 at 06:46

1 Answers1

0

Try to put this code in the top-most part of your PHP page.

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Jake
  • 135
  • 1
  • 11
  • It works but it also prevent access from anchor tag. – Mohit Mar 25 '16 at 06:47
  • what is "BASEPATH" here? – Mohit Mar 25 '16 at 09:46
  • Sorry for that. It was a global var I used that points to the system base path. You can defined your own BASEPATH and use it to check to accept or deny direct access to a PHP file. This is a common process that is being used by most applications like CodeIgniter, Joomla, WordPress, etc. – Jake Mar 28 '16 at 04:58