[英]How can I get a username from LDAP?
I'd like to ask you how can i dinamically get a username from ldap. 我想问你怎样才能从ldap获得用户名。 As you can see below, i entered the username 'smith2' 如下所示,我输入了用户名'smith2'
$_SERVER["REMOTE_USER"] = 'smith2';
$param = $_SERVER["REMOTE_USER"]
And I can get his first name, like this: 我可以得到他的名字,如下:
$ldap1 = new ldapl;
$fname=$ldap1->getFname($param);
This is useful because I have some forms with some fields which are filled by default (name, first name, etc). 这很有用,因为我有一些表单,其中包含一些默认填充的字段(名称,名字等)。
It must be dynamic. 它必须是动态的。 Each person has a PC, so the person Y should see his name, first name, etc The person X his name, first name, etc. 每个人都有一台电脑,所以Y的人应该看到他的名字,名字等。他的姓名,名字等等。
But i don't know how to get the username dinamically. 但我不知道如何获得用户名dinamically。 Can you explain it to me? 你能解释一下吗?
Thanks 谢谢
You can request the username via an AJAX call: 您可以通过AJAX调用请求用户名:
var remote_user = '';
$.get('path/to/server-side.php', function (response) {
remote_user = response;
/*you can populate your forms with information returned from your PHP script*/
});
This code will request information from a PHP script. 此代码将从PHP脚本请求信息。 Your PHP script could just output $_SERVER['REMOTE_USER']
and that will be the response
variable in the AJAX callback. 您的PHP脚本只能输出$_SERVER['REMOTE_USER']
,这将是AJAX回调中的response
变量。
A good way to communicate between PHP script and JavaScript is to use the PHP function json_encode()
to output your server response. 在PHP脚本和JavaScript之间进行通信的一种好方法是使用PHP函数json_encode()
来输出服务器响应。 Then use the jQuery method $.getJSON()
which will automatically parse the response into a JavaScript object that can be iterated through. 然后使用jQuery方法$.getJSON()
,它将自动将响应解析为可以迭代的JavaScript对象。
Documentation for $.get()
: http://api.jquery.com/jquery.get $.get()
文档: http : //api.jquery.com/jquery.get
Documentation for json_encode()
: http://www.php.net/json_encode json_encode()
文档: http : json_encode()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.