PHP 8.5.0 Alpha 4 available for testing

Voting

: nine minus two?
(Example: nine)

The Note You're Voting On

Sami Oksanen
21 years ago
I edited Jon Caplinger's code which is located below (date: 09-Nov-2002 05:44).

- I corrected line
"if (!($connect=@ldap_connect($ldap))) {" with
"if (!($connect=@ldap_connect($ldap_server))) {"

- Removed $name-attribute

- "Name is:"-field was always an Array, so I changed printing line to:
" echo "Name is: ". $info[$i]["name"][0]."<br>";"

I also added some alternative search filters to try out.

Here is the code:

<?php

$ldap_server
= "ldap://foo.bar.net";
$auth_user = "[email protected]";
$auth_pass = "mypassword";

// Set the base dn to search the entire directory.

$base_dn = "DC=bar, DC=net";

// Show only user persons
$filter = "(&(objectClass=user)(objectCategory=person)(cn=*))";

// Enable to show only users
// $filter = "(&(objectClass=user)(cn=$*))";

// Enable to show everything
// $filter = "(cn=*)";

// connect to server

if (!($connect=@ldap_connect($ldap_server))) {
die(
"Could not connect to ldap server");
}

// bind to server

if (!($bind=@ldap_bind($connect, $auth_user, $auth_pass))) {
die(
"Unable to bind to server");
}

//if (!($bind=@ldap_bind($connect))) {
// die("Unable to bind to server");
//}

// search active directory

if (!($search=@ldap_search($connect, $base_dn, $filter))) {
die(
"Unable to search ldap server");
}

$number_returned = ldap_count_entries($connect,$search);
$info = ldap_get_entries($connect, $search);

echo
"The number of entries returned is ". $number_returned."<p>";

for (
$i=0; $i<$info["count"]; $i++) {
echo
"Name is: ". $info[$i]["name"][0]."<br>";
echo
"Display name is: ". $info[$i]["displayname"][0]."<br>";
echo
"Email is: ". $info[$i]["mail"][0]."<br>";
echo
"Telephone number is: ". $info[$i]["telephonenumber"][0]."<p>";
}
?>

<< Back to user notes page

To Top