简体   繁体   English

PHP LDAP认证为

[英]PHP LDAP Authenticated as

is this possible to show who is authenticated after the login ? 这可以显示登录后经过身份验证的人吗?

my code contains the login and is working: 我的代码包含登录名并且正在运行:

html: 的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:

<?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";
}

when i start the ldp.exe programm it shows me the ldp.exe: 当我启动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'.

the question is how can i extract and render it to the html page who i correctly autheticated. 问题是如何提取并呈现给正确认证的html页面。

for the record: solution for my problem: I put the code between the if statement 记录:解决我的问题的方法:我将代码放在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";
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM