0

I'm using adLDAP to logon to an intranet-site I'm building. I've just startet with LDAP integration, and I am relatively fresh in this game.

I've managed to authenticate and log on using the adLDAP library, but I want to display the users full name when they have logged in.

Heres the login-script I'm using. Basically the same as the adLDAP example.

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

?>

On the logged-in page I have this code:

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

    include ("main.php");

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

And in main.php I try to include something like

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

How can I display the logged in users full name here?

Thanks!

Tngld
  • 153
  • 13

1 Answers1

0

The property you are looking for in adldap is displayName.

Check the documentation: http://adldap.sourceforge.net/wiki/doku.php?id=documentation_user_functions#infocollection_username_fields_null

Marcel Burkhard
  • 3,453
  • 1
  • 29
  • 35
  • Thank you, but how do I use this? simply echo $_SESSION['displayName']? – Tngld Apr 17 '15 at 09:21
  • It's described here: http://adldap.sourceforge.net/wiki/doku.php?id=documentation_user_functions#infocollection_username_fields_null – Marcel Burkhard Apr 17 '15 at 09:23
  • I'm having a hard-time understanding this... I've put this on top of the logged-in page now: `user()->infoCollection($username, array('*')); ?>` and this to display the name: `displayName; ?>`. But this makes the page crash... Am I completely failing at understanding this? – Tngld Apr 17 '15 at 09:41
  • 1
    Nm, I got it finally :) – Tngld Apr 17 '15 at 10:35
  • hi @Thorbj i tried getting the user name too using adldap, but it returns empty. may i know how do you solve it? do you mind sharing your code snippet? – Slay Jul 09 '15 at 09:08
  • 1
    Sure @Slay! Sorry for the late response btw! In main.php I used this: `Welcome ` and in auth.php I have this: `//authenticate the user if ($adldap->authenticate($username, $password) and $adldap->user()->inGroup($username,"First Group Name") or $adldap->user()->inGroup($username,"Secondary Group Name")){` and finally this before $redir...: `$user = $adldap->user()->infoCollection($username, array('*')); $_SESSION["user"] = $user->displayName;` I hope I haven't forgotten anything now... :) – Tngld Jul 22 '15 at 08:57
  • thanks for the follow up! @Thorbj i managed to get it working already! – Slay Jul 22 '15 at 09:06