2017-07-03 283 views
0

是否可以顯示登錄後身份驗證的人員?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 PROGRAMM它讓我看到 自民黨。 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頁面。

+0

當然,你可以只'回聲$ username'顯示誰是登錄的代碼?將該值存儲在'$ _SESSION'中以在其他頁面中引用它。 – timclutton

回答

0

備案:解決我的問題: 我把之間的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"; 
    }