How can I get a user's input when using htaccess/htpasswd?

南笙酒味 提交于 2019-11-30 17:03:47

You just need the following to get the username that is currently in use for an authenticated session:

$_SERVER['PHP_AUTH_USER']

rev1

In light of @Ben's comment I've now found the section in the PHP documentation at HTTP authentication with PHP that explains what's going on:

As of PHP 4.3.0, in order to prevent someone from writing a script which reveals the password for a page that was authenticated through a traditional external mechanism, the PHP_AUTH variables will not be set if external authentication is enabled for that particular page and safe mode is enabled. Regardless, REMOTE_USER can be used to identify the externally-authenticated user. So, you can use _SERVER['REMOTE_USER'].

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!