.htaccess + php auth.
Just wondering if it is possible to grab the username and password entered into the .htaccess window when someone is trying to access a directory/file using php?
Basically, I'd like to do some kind of "Welcome " based on who logged in via the .htaccess . Does .htaccess pass them on in a variable, maybe something like $HTTP_ACCESS_VARS["user"] ???
Thanks in advance...
(first post here, yay)
Mark D.B.D posted this at 17:46 — 31st March 2002.
They have: 9 posts
Joined: Mar 2002
<?php
function authenticate() {
header( \"WWW-Authenticate: Basic realm=\\"Test Authentication System\\"\");
header( \"HTTP/1.0 401 Unauthorized\");
echo \"You must enter a valid login ID and password to access this resource\n\";
exit;
}
if (!isset($PHP_AUTH_USER) || ($SeenBefore == 1 && !strcmp($OldAuth, $PHP_AUTH_USER))) {
authenticate();
}
else {
echo \"<p>Welcome: $PHP_AUTH_USER<br>\";
echo \"Old: $OldAuth\";
echo \"<form action='$PHP_SELF' METHOD='POST'>\n\";
echo \"<input type='hidden' name='SeenBefore' value='1'>\n\";
echo \"<input type='hidden' name='OldAuth' value='$PHP_AUTH_USER'>\n\";
echo \"<input type='submit' value='Re Authenticate'>\n\";
echo \"</form></p>\n\";
}
?>
More info: http://www.php.net/manual/en/features.http-auth.php
peterd posted this at 19:31 — 31st March 2002.
They have: 4 posts
Joined: Mar 2002
Brill! thanks alot.
Mark D.B.D posted this at 22:49 — 31st March 2002.
They have: 9 posts
Joined: Mar 2002
np
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.