Just starting with PHP... like... yesterday.
I'm trying to create a page that will use LDAP values to determine what pages/functionality the user is allowed to view. i.e. if the logging user if a memberOf 'Accounting' they get some tools that 'HR' would not.
So, I figured I'd start off by just creating a page that displays all available attributes and their values for the user logging in. Now, I'm really hung up on displaying the values - everything just says 'Array' if I try to use the ldap_get_attributes() function in conjunction with array that is created from ldap_get_values. I could very well be approaching it all wrong, here we go (most code started from php.net)...
Code: Select all
<html>
<body>
<?
$logName = $_POST['logName'];
$passwd = $_POST['passwd'];
echo "<h3>LDAP query test</h3>";
echo "Connecting ...";
$ds=ldap_connect($IPofMyLDAPServer); // must be a valid LDAP server!
echo "connect result is " . $ds . "<br />";
if ($ds) {
echo "Binding ...";
$r=ldap_bind($ds,'domain prefix\\' . $logName,$passwd);
echo "Bind result is " . $r . "<br />";
echo "Searching for (account=$logName) ...";
$sr=ldap_search($ds, "DC=subdomain,DC=domain,DC=edu", "samaccountname=$logName");
echo "Search result is " . $sr . "<br />";
echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "<br />";
echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for " . $info["count"] . " items returned:<p>";
for ($i=0; $i<$info["count"]; $i++) {
echo "dn is: " . $info[$i]["dn"] . "<br />";
echo "first cn entry is: " . $info[$i]["cn"][0] . "<br /><br />";
}
$entry = ldap_first_entry($ds, $sr);
$attrs = ldap_get_attributes($ds, $entry);
for ($x=0; $x<$info["count"]; $x++){
for ($y=0; $y<$attrs["count"]; $y++){
echo $attrs[$y] . " = " . $info[$x][strtolower($attrs[$y])] . "<br />";
}
echo "<hr />";
}
echo "Closing connection";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
?>
</body>
</html>Code: Select all
LDAP query test
Connecting ...connect result is Resource id #2
Binding ...Bind result is 1
Searching for (account=hhsuser1) ...Search result is Resource id #3
Number of entires returned is 1
Getting entries ...
Data for 1 items returned:
dn is: CN=HHS\,USER1,OU=My OU,OU=Level Up OU,DC=subdomain,DC=domain,DC=EDU
first cn entry is: HHS,USER1
objectClass = Array
cn = Array
sn = Array
givenName = Array
distinguishedName = Array
instanceType = Array
whenCreated = Array
whenChanged = Array
displayName = Array
uSNCreated = Array
memberOf = Array
uSNChanged = Array
name = Array
objectGUID = Array
userAccountControl = Array
badPwdCount = Array
codePage = Array
countryCode = Array
badPasswordTime = Array
lastLogoff = Array
lastLogon = Array
scriptPath = Array
pwdLastSet = Array
primaryGroupID = Array
objectSid = Array
accountExpires = Array
logonCount = Array
sAMAccountName = Array
sAMAccountType = Array
userPrincipalName = Array
objectCategory = Array
lastLogonTimestamp = Array
Closing connectionAny help would be much appreciated, thanks!