9 Replies - 3964 Views - Last Post: 27 July 2010 - 11:05 AM

#1 Guest_DecafJava*


Reputation:

PHP/UNIX Directory IndexIgnore Problem

Posted 26 July 2010 - 10:08 PM

I have PHP scripts in my website that reside in a folder called Scripts. I am trying to make it so that no one can type http://www.mywebsiteurl.com/Scripts and be able to see all the files in there via the browser.

Now I know that to do this, I need to create a .htaccess file in the Scripts directory and add either one of these two lines in there:

IndexIgnore .htaccess
IndexIgnore *.php



Both of these do the job just well and hide files from showing through the browser. However, when I do this, then I can't even access the scripts anymore, and other pages that implicitly call those scripts in the Scripts folder are not able to run those scripts properly (i.e., I end up with a blank screen).

Any ideas how to hide the directories from being browsed AND have my scripts still work?

Is This A Good Question/Topic? 0

Replies To: PHP/UNIX Directory IndexIgnore Problem

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,443
  • Joined: 10-May 07

Re: PHP/UNIX Directory IndexIgnore Problem

Posted 26 July 2010 - 10:14 PM

I would configure Apache to disable directory browsing. Assuming that's the web server software you are using on this.

Alternatively you can add the following to .htaccess under that directory :
Options -Indexes

Since this question has nothing to do with PHP code, this topic really should be posted under WebServers & Hosting. I'll go ahead & move it there.
Was This Post Helpful? 1
  • +
  • -

#3 Guest_decafjava*


Reputation:

Re: PHP/UNIX Directory IndexIgnore Problem

Posted 27 July 2010 - 01:56 AM

yeah, that, too, does the job with hiding the contents from being visible in the browser...but then i can't even execute those scripts! what i need is a way to hide them but still be able to call those scripts from other scripts and have them run successfully (not have the screen turn white!)
Was This Post Helpful? 0

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,443
  • Joined: 10-May 07

Re: PHP/UNIX Directory IndexIgnore Problem

Posted 27 July 2010 - 02:04 AM

Describe "can't execute the scripts". The reason you want the server to not allow browsing is because this will not interfere with the directory structure.

Since you are on a Unix file system, the 1st thing I would look at is the executing user (for the web service) & the permissions of the directory structure. Does the executing user have the correct permissions of the files & directories?
Was This Post Helpful? 0
  • +
  • -

#5 Guest_DecafJava*


Reputation:

Re: PHP/UNIX Directory IndexIgnore Problem

Posted 27 July 2010 - 03:09 AM

okay so basically, when i do the Options command you said, then when i go to the Scripts directory in the browser, it says Permission Denied and doesn't show the directory listing of all the files (good! this is what i want)...BUT...

once i do that, then say the scripts folder has a script inside called myscript.php, whenever i try to run that script, it does not work (it displays a white screen and halts)...but before changing the Options setting, the scripts worked fine (so it's definitely not from my scripts)

basically, i want to hide the files from being listed BUT if i manually want to access the file in that Scripts folder by typing its full ....../Scripts/myscript.php path in the browser, i want it to let me do so (and not give that same Permission Denied)

and yes, i am the owner of all the files and directories on the server
Was This Post Helpful? 0

#6 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,443
  • Joined: 10-May 07

Re: PHP/UNIX Directory IndexIgnore Problem

Posted 27 July 2010 - 03:17 AM

View PostDecafJava, on 27 July 2010 - 04:09 AM, said:

whenever i try to run that script, it does not work (it displays a white screen and halts)


White page means the PHP code failed. Without seeing the code it's impossible to say if it's a permissions issue or an issue with the code. Can you post our code (or at least the relevant portions) using code tags? Thank you.

:code:
Was This Post Helpful? 0
  • +
  • -

#7 Guest_DecafJava*


Reputation:

Re: PHP/UNIX Directory IndexIgnore Problem

Posted 27 July 2010 - 10:36 AM

i'm sorry, when i said "blank white screen", yes, you are right...that occurs when PHP code fails...well i had explained it incorrectly, the screen doesn't turn white, but shows the same white Permission Denied screen. i get that screen when i try to individually run a specific script.php file within that Scripts folder. this is the problem i am having: whenever i disable the directory browsing, i cannot access any of my scripts (not even individually by typing its url)
Was This Post Helpful? 0

#8 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,443
  • Joined: 10-May 07

Re: PHP/UNIX Directory IndexIgnore Problem

Posted 27 July 2010 - 11:00 AM

Sounds like you locked down the file &/or folder permissions. Check the tutorial that I provided in the previous post that will show you how your folders should be set.

If you can't get it, we'll need to see the output of ls -l on the folders to see what's set incorrectly.
Was This Post Helpful? 0
  • +
  • -

#9 Guest_DecafJava*


Reputation:

Re: PHP/UNIX Directory IndexIgnore Problem

Posted 27 July 2010 - 11:03 AM

my permissions are fine...and i finally figured it out:

what i need to put in my .htaccess file is
deny from all
, not
Options -Indexes


thanks anyway for your responses, appreciate the effort!
Was This Post Helpful? 0

#10 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6821
  • View blog
  • Posts: 31,443
  • Joined: 10-May 07

Re: PHP/UNIX Directory IndexIgnore Problem

Posted 27 July 2010 - 11:05 AM

Glad you got it figured out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1