Prevent directory and file access

Discussion in 'PHP' started by Cinta April, Apr 15, 2008.

  1. #1
    How do I prevent someone from reading my files by directly typing the url of my file?
     
    Cinta April, Apr 15, 2008 IP
  2. PHPGator

    PHPGator Banned

    Messages:
    4,437
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    260
    #2
    if you have a cpanel account you should be able to easily put these protected files in a directory and then password protect the directory.

    If you are totally confused but know that you have a cpanel account I will be more than happy to do it for you for $5.00 - $10.00 :)
     
    PHPGator, Apr 15, 2008 IP
  3. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here is two simple ways which you can do:

    1. Create a blank index.html and upload to directory which you don't want to be listed.

    2. Create a file named .htaccess and put the following line of text into that file
    Options All -Indexes
    Code (markup):
    Then upload it to your public_html directory.
     
    Vbot, Apr 15, 2008 IP
  4. Cinta April

    Cinta April Banned

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    doesn't work I seem to be able to read my file. How do I prevent someone from reading my text files when I upload it to a server?
     
    Cinta April, Apr 16, 2008 IP
  5. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #5
    please read more about mod_rewrite..
    ill post the link later
     
    bartolay13, Apr 16, 2008 IP
  6. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Oops, I thought you want to disable directory listing :D
    Here is the actual code that you need.

    put this in your .htaccess file:
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} ^$
    RewriteRule \.(txt)$ - [F]
    </IfModule>
    Code (markup):
    that will stop people from directly typing the url of my file .txt files, but it doesn't prevent hotlinking though.
     
    Vbot, Apr 16, 2008 IP