php http身份验证:每次加载网站时都要求输入密码?

发布于 2024-10-09 22:10:25 字数 66 浏览 3 评论 0原文

我的问题是:

我在 php 中该怎么做,每次加载网站时都会要求 http 身份验证,而不仅仅是第一次?

my question is:

how can i do in php, that EVERY TIME a website is loaded it asks for the http authentication and not just the first time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不念旧人 2024-10-16 22:10:25

我相信您指的是基本身份验证

浏览器提供身份验证,您完全无法控制它。您不能使用此方法来满足您的要求,必须使用另一种方法。

从技术上讲,如果浏览器未提供正确的凭据,您的脚本不应允许访问资源。浏览器为访问的每个资源提供凭据。但是,通常每个浏览器使用会话只会提示用户一次。

您可以在这里阅读:http://www.php。 net/manual/en/features.http-auth.php#100396

I believe you are referring to basic auth.

The browser provides authentication, and you have absolutely no control over it. You cannot use this method for what you are asking, you must use another.

Technically speaking, your script shouldn't be allowing access to the resource if the browser doesn't provide proper credentials. The browser provides credentials for each resource accessed. But, the user will only be prompted once per browser usage session, generally.

You can read about it here: http://www.php.net/manual/en/features.http-auth.php#100396

娇柔作态 2024-10-16 22:10:25

您必须更改密码和/或用户名和/或身份验证领域。浏览器决定存储密码,因此您可能无能为力。

You would have to change the password and/or username and/or authentication realm. The browser decides to store the password, so there's probably not much else you can do.

零崎曲识 2024-10-16 22:10:25

你的 PHP 已经做到了这一点!然而,人们的浏览器将缓存他们的用户名/密码输入,并在整个会话期间自动提供它。这是为了避免用户感到非常恼火。您无法控制这种行为。

也许您可能会考虑另一种授权方法,尽管我想不出一种可以可靠地按照您的意愿执行的方法。无论如何,HTTP 上的安全性是毫无用处的,所以你最好不要打扰。

Your PHP already does this! However, people's browsers will cache their username/password input and provide it automatically throughout that session. This is to save the users getting horrifically annoyed. You have no control over this behaviour.

Perhaps you might consider an alternative authorisation approach, though I can't think of one that would reliably perform as you desire. Security over HTTP is pretty useless anyway so you might as well not bother.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文