php 使用PHP检测哪个htaccess用户登录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4787261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use PHP to detect which htaccess user signed in?
提问by nkcmr
I'm constructing an upload so people I know can send me files securely, and with ease. But I want to design it just so, that when one of my friends sign in with theirsign-in (it's going to an .htaccess
login), I can establish that in PHP and log their file into a database associated with their account.
我正在构建一个上传文件,以便我认识的人可以安全、轻松地向我发送文件。但我想这样设计,当我的一个朋友使用他们的登录名登录时(它将.htaccess
登录),我可以在 PHP 中建立它并将他们的文件登录到与他们的帐户关联的数据库中。
In short, I need PHP to be able to detect who is signed in so I can pass that data to a database.
简而言之,我需要 PHP 能够检测到谁登录,以便我可以将该数据传递到数据库。
Is there any possible way of doing that?
有什么可能的方法吗?
回答by Michael Irigoyen
You should be able to get the user name the user signed in with from the $_SERVER['REMOTE_USER']
variable after they've successfully signed in.
在用户$_SERVER['REMOTE_USER']
成功登录后,您应该能够从变量中获取用户登录时使用的用户名。
回答by Marc B
You'd want $_SERVER['PHP_AUTH_USER']
and $_SERVER['PHP_AUTH_PW']
to retrieve the username and password, assuming you mean a regular "basic authentication" login, as done by Require valid-user
settings in .htaccess.
您想要$_SERVER['PHP_AUTH_USER']
并$_SERVER['PHP_AUTH_PW']
检索用户名和密码,假设您的意思是常规“基本身份验证”登录,如Require valid-user
.htaccess 中的设置所做的那样。
more details here.
更多细节在这里。
回答by Onkar Parmar
Something that worked for me:
对我有用的东西:
$_SERVER['REDIRECT_REMOTE_USER']
Please try the above. In general, one can do "print_r($_SERVER)
" and hunt out the parameter one is looking for.
请尝试以上方法。通常,可以执行 " print_r($_SERVER)
" 并找出正在寻找的参数。
回答by Mano Kovacs
You can read it from $_SERVER['PHP_AUTH_USER']
你可以从 $_SERVER['PHP_AUTH_USER']
回答by Jose Vega
I think the following variables give you the derise information:
我认为以下变量为您提供了嘲笑信息:
PHP_AUTH_USER:When doing HTTP authentication this variable is set to the username provided by the user.
PHP_AUTH_USER:在进行 HTTP 身份验证时,此变量设置为用户提供的用户名。
PHP_AUTH_PW:When doing HTTP authentication this variable is set to the password provided by the user.
PHP_AUTH_PW:在进行 HTTP 身份验证时,此变量设置为用户提供的密码。
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
回答by espradley
Not to open up an old task, but running PHP 5 with Apache 2.2 and this is the variable that works for me:
不是打开旧任务,而是使用 Apache 2.2 运行 PHP 5,这是对我有用的变量:
$_SERVER['USER'];