Page 1 of 1

php and .htaccess

Posted: Tue Oct 07, 2014 5:40 am
by UnderMiner
Hi,
I'm totally new to making web pages and have a small site (http://www.mazzocco.dk) where I have a few things located that people can download.
I've made a folder there called "Sheila" that I have protected with a .htaccess file and.htpasswd file I made. Now the question is:
How do I go about displayinging my custom 401page.php?
I don't just want the "normal" error page to display, but my own made page, when people type in the wrong user name/password
My .htaccess file:
AuthName "User Name And Password"
AuthType Basic
AuthUserFile /customers/0/4/f/mazzocco.dk/httpd.www/Sheila/.htpasswd
AuthGroupFile /dev/null
require valid-user

I want it to display this file when wrong information is entered:
<html>
<head>
<meta http-equiv="refresh" content="3; URL=http://mazzocco.dk/">
<meta name="keywords" content="automatic redirection">
</head>
<body>
<center><font size="+2">Restircted area<BR>
If your browser doesn't automatically return you<BR>
to the main page within a few seconds you may want<BR>
to go to <a href="http://mazzocco.dk/">the destination</a>
manually.</font></center>
<center><img src="access.jpg"</img></center>
</body>
</html>

But I want it to make a directory listing from my normal index.php file (like it looks in all the non-password protected folders) when the right information is entered in the authentication box that is displayed.
In case it cannot be done, what do I need to type in my .htaccess file for it to display a message that I make when wrong information is entered?

Thanks in advance and sorry if this is the wrong place to ask such a question but I've exhausted my web searches and they didn't turn up the information I needed

Re: php and .htaccess

Posted: Tue Oct 07, 2014 7:12 am
by Celauran
Have you added an ErrorDocument directive to your .htaccess?

Re: php and .htaccess

Posted: Wed Oct 08, 2014 11:23 pm
by UnderMiner
I have tried that yes,
ErrorDocument 401 /Sheila/401page.php
This only results in the page not loading at all. Sorry I didn't mention that earlier.
If you have other suggestions I'm all ears (eyes in this case :))

Re: php and .htaccess

Posted: Wed Oct 08, 2014 11:41 pm
by requinix
I don't know what all Apache will do when serving the 401 page, but at best you simply need to send a 401 Unauthorized header - that's what triggers the username/password dialog. Otherwise PHP will send its own 200 OK, that it normally does, and the browser won't know what to do.

Code: Select all

header("HTTP/1.1 401 Unauthorized");