Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking at quickly password protecting a website, one folder on a server. I have played around with .htaccess and just realised that it's probably not working because it's likely it's sat on a windows server running PHP. I'am assumming this also means I can't use authenticate in PHP. Does any have any suggestions on a simple proctect I can implement in this scenario ? Thanks.

share|improve this question

migrated from Aug 18 '10 at 17:28

This question came from our site for professional and enthusiast programmers.

I meant .htaccess :) – owen Aug 18 '10 at 13:23
What webserver software are you using? (IIS? Apache? Something else?) – Rowland Shaw Aug 18 '10 at 13:24
Hi, I'm told it's IIS (I'm locked out from that) – owen Aug 18 '10 at 13:28
check out SF:… – webbiedave Aug 18 '10 at 13:34
Thanks, think I may go down the route of building / using a PHP login script. – owen Aug 18 '10 at 13:43

Basic access authentication is not OS-specific. It's part of the HTTP standard, but the implementation details are webserver specific. .htaccess is how the Apacheweb server implements this (and other features). If you can do other things (like URL rewriting) via .htaccess, then authentication should also work. If not, you have to find out what webserver you're using (probably IIS) and how to configure basic auth there.

share|improve this answer
Hmm, found out the hosting is with fasthosts - I can get into the panel but they charge for being able to configure basic auth. Is there anything I can do in PHP to achieve the same thing ? – owen Aug 18 '10 at 13:35

If you're wanting to solve the problem in PHP solely, you could set a 'landing' page that requires a login or just password entry. Set up a cookie to store that information, then have each page check for the cookie. That's the way I would do it if I couldn't change the .htaccess file or wanted a PHP-only solution.

share|improve this answer
Cheers, that sounds like a plan. – owen Aug 18 '10 at 13:45
note that this doesn't protect access from non-HTML/PHP files in your folder. You might want to move such files to a folder outside the webroot and forward them via a PHP site protected as Saladin describes it. – Anonymous Aug 18 '10 at 13:52
@nicolas78 Good point there. I didn't think of non-HTML/PHP content. – Saladin Akara Aug 18 '10 at 14:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.