蓝宝石 / 基本HTTP认证
简单的基本HTTP认证。无需框架。
此包的规范存储库似乎已不存在,因此已冻结该包。
1.0.1
2015-11-16 16:47 UTC
This package is not auto-updated.
Last update: 2023-03-04 10:10:10 UTC
README
这是一个提供基本HTTP认证的简单函数。
请注意,基本HTTP认证不是安全的。它在网络中明文传输用户名和密码(可能通过HTTPS是安全的,但我不懂安全专家)。
它通常被认为是一种糟糕的用户体验。
所以,话虽如此,如果你仍然想使用基本HTTP认证,那么...
让我们开始吧
使用composer包含此项目
$ composer require saffyre/basic-http-authentication
根据您的设置,您可能需要使用php composer.phar
而不是composer
。您还可以手动将"saffyre/basic-http-authentication": "^1.0"
添加到您的composer.json文件中。这不是一个composer教程,所以请查找相关资料。
以下是使用方法
<?php $success = \Saffyre\basicHttpAuth("Please log in.", function($username, $password) { // Validate the username and password. // You might connect to a database or read a file on your server, etc. // Return 'true' if the user authenticates successfully. return $username == 'admin' && $password == 'pass123'; }); if ($success) { // The user is logged in, do your thing. echo "Welcome."; } else { // The user clicked "Cancel" in the login box or is otherwise not logged in. // Show some kind of error message. echo "Please log in to continue."; }
就这么多。祝您认证愉快!