how we protect directory and its files

Discussion in 'PHP' started by neerajkumarsharma, Feb 27, 2009.

  1. #1
    Dear,
    I want to protect a directory folder and its files(.php & .html) without using linex.plz short out this problem.
     
    neerajkumarsharma, Feb 27, 2009 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    The answer is most likely to use an .htaccess file, especially when .html files are involved.

    What does 'protect' mean exactly? You don't want anyone but a select few to have access to those files? Don't want people to be able extract the files themselves? Something else?
     
    plog, Feb 27, 2009 IP
  3. canishk

    canishk Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    if you are trying to protect your program directories (javascript, phpclass) and stylesheets(css), you better give permission as 0755 and also create a index file inside so that if someone tried to visit those folders using port 21 (http) they will redirect by giving following code.

    
    <script language="JavaScript">
    	function redirect()
    	{
    		top.location	= "yoursitename.com";
    	}
    	function countdown()
    	{
    	setTimeout('redirect()', 5000);
    	}
    </script
    
    Code (markup):
    put it inside head part of the html.
     
    canishk, Feb 27, 2009 IP
  4. canishk

    canishk Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    in case of images you can try htaccess

    upload a .htaccess file into your image folder having the following code

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://yourdomain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com/.*$ [NC]
    RewriteRule .*\.(gif|GIF|jpg|JPG|bmp|BMP)$ - [F]
    
    Code (markup):
    Change "yourdomain.com" to your own URL, and upload the .htaccess file to the directory containing your images.
     
    canishk, Feb 27, 2009 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Also, put a blank index.html in every folder that doesn't contain any a main webpage file such as index.html / default.html

    - ads2help
     
    ads2help, Feb 28, 2009 IP