how to block direct access to a .php file

Page Title Module
Move Remove Collapse

Unconfigured Ad Widget

Unconfigured Ad Widget Module
Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to block direct access to a .php file

    hi friends,
    if i want to block direct access to test.php file what should i do,

    example: if any one type directly this http://mydomain.com/test.php in browser it must redirect to home page

    is there any code for this

  • #2
    its too easy.....jast add this code in your .htaccess file
    ErrorDocument 403 /index.php
    ErrorDocument 404 /index.php
    ErrorDocument 500 /index.php

    Comment


    • #3
      i think u didn't get my point .....i asked to block test.php when it is visitors directly type in browser like http://mydomain.com/test.php if they type this only directly it should redirect to home page ,

      or consider like this i have my.php file and linked test.php in that file ...now test.php must be open if it clicked from my.php .....otherwise it should redirect to home page

      Comment


      • #4
        SetEnvIf REFERER "www.mydomain.com/my.php" linked_from_here
        SetEnvIf REFERER "^$" linked_from_here

        <Files ~ "test.php">
        Order deny,allow
        Deny from all
        Allow from env=linked_from_here
        </Files>


        is this correct

        Comment


        • #5
          I take it the php file is included in another script
          so you would probably add something like:
          PHP Code:
          if($_SERVER['REQUEST_URI']=="/test.php"){
          header("Location: /index.php");
          exit;

          Last edited by something else; 05-07-10, 17:50.

          Comment


          • #6
            what do you mean? can u explain clearly

            Comment


            • #7
              my above code is for a php page if it actually exists but you dont want nobody going on it directly ...only way to get on that page is via another page by using include('test.php'); or some other similar way

              if the page doesnt exist then use sanju`s suggestion in .htaccess
              ErrorDocument 404 /index.php

              Comment


              • #8
                Hmmmmm.....after tried several methods i got solution by using $_SERVER['PHP_SELF']; and $_SERVER['HTTP_REFERER']; ........please close this thread

                Comment

                Working...
                X