简体   繁体   中英

Apache Digest/Basic Login Through PHP

I'm trying to figure out if there is a way to get PHP to log into Apache for a user. So if the user supplies a valid username and password on an HTML form, PHP would login with credentials. So, something like:

<?php 
if ($_POST["user"] == "john" && $_POST["pass"] == "swordfish"){
   apache_login($_POST["user"], $_POST["pass"]);
}
?>

What I'm trying to do is have some kind of login security on Apache in order to protect files but I want to avoid having that username/password pop up that Apache uses to get the credentials.

I want them to fill in their info in an HTML form and have PHP take care of the authentication before they can view any files, that way someone can't just put "http://example.com/files/private.doc" in the url and get a file.

Thanks in advance!

Have you tried http://comp.uark.edu/~ajarthu/mod_auth_form/ This adds form-based login for basic authentication. The author states that Apache will have a native capability for this in v2.4 (see https://httpd.apache.org/docs/2.4/mod/mod_auth_form.html )

Read about the Apache Request Processing Model .

Security comes before Handler, the latter of which is where PHP is invoked. If Apache requires authentication for a specific resource requested by a client, this requirement must be fulfilled before the PHP handler is invoked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM