I have a question in regards to LDAP implementation using PHP. I just recently started reading up on LDAP and am still having trouble understanding how it works. I am developing a new application that will grant access to users only if they are found in Active directory. The code I have posted below determines if the username and password the user enters is in Active Directory. This code works, however now I would like to pull the first name of the user based on what credentials were entered. The reason I would like to pull this information is so that when the user logs in they are redirected to another page (ie. dashboard.php) that will display content and the phrase "Welcome "First Name of User". I am just not sure how I would have to go about pulling this information. If anyone could provided feedback on how I should go about doing this it would be greatly appreciated.
Connecting to LDAP sever:
<?php
$ldaphost = "name of host"; //LDAP Host
$ldapport = 389; //LDAP Port Number
$ldapconn = ldap_connect($ldaphost, $ldapport); //Connect to LDAP Host on LDAP Port Number
// Check LDAP connection
if(!$ldapconn) {
die("Unsuccessful connection to " . $ldaphost . " on port " . $ldapport . "<br />");
}
?>
Validate if user is in Active Directory:
<?php
include 'ldap_connect.php';
$username = $_POST['username'];
$password = $_POST['password'];
$ldapbind = ldap_bind($ldapconn, $username, $password);
if ($ldapbind) {
header("Location: ../dashboard.php");
} else {
print "Access Denied!";
}
?>