views:

67

answers:

3

How do I use PHP to check whether a folder is password protected or not? I am using a PHP script that check for return codes 401 and 403 but when it runs into a folder that is password protected it recognizes that its a 403 but does not allow the popup box for username and password to display? How do I detect that the folder is password protected so I can tell my script to ignore it?

A: 

You say you already have a script to check if the header code is 401 and 403 and yet you want to know how you can check if a page sends a 403 header?

Perhaps you mean talking about the Authentication header.

Alix Axel
+3  A: 

Actually 403 means forbidden. A password-protected resource would normally return 401 Unauthorized.

You already have the information you need: The HTTP response code (403 or whatever) is how you know that the resource (folder, file) is inaccessible.

Nate
A: 

Assuming the server uses standard HTTP Authentication, the page is password protected if following conditions are met,

  1. The response status code is 401.
  2. www-authenticate header is present in response.

Zhihong

ZZ Coder