1

I have create a php page for encrypt with HTTP base authentication, sample code below:

<?php
  if( !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_PW'] != '__PASSWORD__') {
    header('WWW-Authenticate: Basic realm="__REALM__"');
    header('HTTP/1.0 401 Unauthorized');
  }
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <p>hello world</p>
</body>
</html>

Above code works, but browser will presist authentication cache when every time reload the page, so user cannot input password every time page load, So, How to avoid browser to cache authentication?

TangMonk
  • 2,054
  • 1
  • 19
  • 39
  • Have you tried this ? https://stackoverflow.com/questions/4480304/how-to-set-http-headers-for-cache-control – Fran Cerezo Jun 06 '20 at 10:53
  • @FranCerezo Cache control seems not work with HTTP base authentication, I have tried insert meta tag with no-cache in html head, and set no-cache control header with php, not work – TangMonk Jun 06 '20 at 10:57

0 Answers0