Forum Moderators: phranque

Message Too Old, No Replies

How to create a Access Denied script?

I don't want users to access folders such as "images", "scripts", "assets"

         

cosmoyoda

6:55 am on Nov 27, 2007 (gmt 0)

10+ Year Member



Hello,

You've probably noticed that on certain websites it is impossible to access folders that are protected, such as "images", "assets", "scripts" etc for obvious reasons. I was wondering if anyone could tell me how I can do this with my site as well.

I am using PHP with MySQL.

Thanks a lot!

Lexur

7:54 am on Nov 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Access is not protected.
If you weren't able to access this folders, you couldn't see the images in the pages from public folders.

You can't access by some reasons:
- the folder is really password protected (Apache)
- the folder is not listing its contents (Apache)
- the folder has a empty index.html file (cool and simple trick)

Finally, someone could have wrote a script to deny access but is easy with the methods listed before.

cosmoyoda

11:22 pm on Dec 28, 2007 (gmt 0)

10+ Year Member



Yeah, I knew how easy it was to "BLOCK" other users to access folders such as: images, js, css, assets, etc. (You know, folders where public access should not be permitted because this is only a place for us to store the important files for our website to use).

But the thing is, it would be cool if I could use, I know know, maybe change the .htaccess file or something to block access for my users to the whole "assets folder". Basically the "assets" folder is where I place all of my Javascripts, PHP scripts, CSS, Images and etc...

Is there a way to do this easily? Block the whole folder so that it is only used by my website and never accessed by my users? It would be easier this way because I wouldn't need to add a "index.html" to every single folder of the assets folder.

If you guys know a way around this let us know.
Thanks!

stajer

12:39 am on Dec 29, 2007 (gmt 0)

10+ Year Member



I think what you want to do is disable directory browsing from apache. You don't need to use htaccess for this.

jdMorgan

12:51 am on Dec 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One line added to /assets/.htaccess:

Deny from all

This will allow the files in this directory and directories below it to be "included" as files in other files and "pages" on your site, but it will not allow any access to those same resources using HTTP (using the Web via HTTP, in other words).

.htaccess affects HTTP access only, and has no effect on FTP, Telnet, SSH, or any other protocol, and no effect on internal server file reads and writes.

Jim

cosmoyoda

1:07 am on Dec 29, 2007 (gmt 0)

10+ Year Member



That is exactly what I wanted!

It worked like a charm. Thank you so much!