Jump to content

.htaacess authentication


anups

Recommended Posts

I have 3 pages on my website

 

1. http://xyz.com/user.php

2. http://xyz.com/admin.php

3. http://xyz.com/superadmin.php

 

Now I want to show http authentication using ".htaccess" && ".htpasswd"  for "admin.php" & "superadmin.php".

 

I cannot use php code

header('WWW-Authenticate: Basic realm="My Realm"');

 

As per my knowledge http authentication using ".htaccess" files works only on directories not on pages.

 

Please  help me in achieving this.

 

Link to comment
https://forums.phpfreaks.com/topic/239216-htaacess-authentication/
Share on other sites

Wrong.

 

As you stated correctly, the built in authentication works on directories.  Thus you DO want to use php code to restrict access to files -- there is no other option.

 

The ways you can do this with php are described here:  http://php.net/manual/en/features.http-auth.php

 

What's nice about this is that you can use your own user table or file rather than using something like the htpasswd program that requires shell access or some wrapper script and is typically difficult and confusing for people who aren't sysadmins. 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.