0

我正在使用 adLDAP 登录到我正在构建的 Intranet 站点。我刚刚开始使用 LDAP 集成,而且我对这个游戏还比较陌生。

我已经设法使用 adLDAP 库进行身份验证和登录,但我想在用户登录时显示他们的全名。

这是我正在使用的登录脚本。与 adLDAP 示例基本相同。

<?php
//log them out
$logout = $_GET['logout'];
if ($logout == "yes") { //destroy the session
session_start();
$_SESSION = array();
session_destroy();
}

//you should look into using PECL filter or some form of filtering here for POST variables
$username = strtoupper($_POST["username"]); //remove case sensitivity on the username
$password = $_POST["password"];
$formage = $_POST["formage"];

if ($_POST["loginform"]) { //prevent null bind

if ($username != NULL && $password != NULL){
    //include the class and create a connection
    include (dirname(__FILE__) . "/src/adLDAP.php");
    try {
        $adldap = new adLDAP();
    }
    catch (adLDAPException $e) {
        echo $e; 
        exit();   
    }

    //authenticate the user
    if ($adldap->authenticate($username, $password)){
        //establish your session and redirect
        session_start();
        $_SESSION["username"] = $username;
        $_SESSION["loggedin"] = true;
        $redir = "Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedin.php";
        header($redir);
        exit;
    }
}
$failed = 1;
}

?>

在登录页面上,我有以下代码:

<?php
session_start();
?>
<?php
$redir = "Location: /Kart";
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {

    include ("main.php");

} else {
    header($redir);
}
?>

在 main.php 我尝试包含类似的内容

<strong>Welcome </strong><?php printf("<b><i>$firstname $lastname</i></b>"); ?> - <a href="Logout.php">click here to log out</a>!

如何在此处显示已登录用户的全名?

谢谢!

4

1 回答 1

0

您在 adldap 中寻找的属性是displayName

检查文档:http ://adldap.sourceforge.net/wiki/doku.php?id=documentation_user_functions#infocollection_username_fields_null

于 2015-04-17T09:16:28.843 回答