PHP LDAP身份验证为

时间:2017-07-03 10:21:27

标签: php ldap

这可以显示登录后谁经过身份验证吗?

我的代码包含登录名并且正在运行:

HTML:

<form action="index.php" method="POST">
    User:
    <input type="text" name="username" /><br>
    Pwd:
    <input type="password" name="password" /><br>
    <input type="submit" value="Login">
</form>

PHP:

<?php 

$ldapServer = 'ldap://myServer';
$ldapPort = myPort;
$username = $_POST['username']."@myDomain.local";
$password = $_POST['password'];

$connect = ldap_connect($ldapServer, $ldapPort) or die("Connection failed!.");
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);

if (@ldap_bind($connect, $username, $password)) {
   echo "Authenticated";
}
else {
    echo "Wrong Username or Password";
}

当我启动ldp.exe程序时它会显示给我 LDP.EXE:

0 = ldap_set_option(ld, LDAP_OPT_ENCRYPT, 1)
res = ldap_bind_s(ld, NULL, &NtAuthIdentity, NEGOTIATE (1158)); // v.3
    {NtAuthIdentity: User='myUserName'; Pwd=<unavailable>; domain = 'myDomain.local'}
Authenticated as: 'MYDOMAIN\myUser'.

问题是我如何提取并呈现给我正确认证的html页面。

1 个答案:

答案 0 :(得分:1)

记录:我的问题的解决方案: 我把代码放在if语句

之间
$filter = "(samAccountName=$user)";
    $search = ldap_search($connect, $base_dn, $filter);
    $info = ldap_get_entries($connect, $search);
    echo "Logged In";
    for($i=0; $i<$info["count"]; $i++) {
        if($info['count'] > 1) break;
        echo "<p>Hello, <strong> ". $info[$i]["sn"][0] .", " . $info[$i]["givenname"][0] ."</strong><br /> (" . $info[$i]["samaccountname"][0] .")</p>\n";
    }