简体   繁体   中英

PHP: fopen to check whether client has authenticated with a password protected file (htpasswd)

Say I have a directory protected using htpasswd called /secret

A valid user logs into /secret.

They are redirected back to a public area.

From within that public area, is there a way within PHP to know whether the current user has authenticated with htpasswd?

Thanks for your time!

Inside the /secret folder, you could have the index page set a session and check that from the public area.

For example, in PHP:

/secret/index.php

<?php
session_start();
$_SESSION['htpasswdAuth'] = true;
header("Location: /public/area");
?>

Then your other scripts can do something like:

<?php
session_start();

if(isset($_SESSION['htpasswdAuth']) && $_SESSION['htpasswdAuth'] == true)
{
    echo 'hello authenticated user!';
}
?>

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