20070924 eldapo does php - plembo/onemoretech GitHub Wiki

title: eldapo does php link: https://onemoretech.wordpress.com/2007/09/24/eldapo-does-php/ author: lembobro description: post_id: 635 created: 2007/09/24 20:12:41 created_gmt: 2007/09/24 20:12:41 comment_status: open post_name: eldapo-does-php status: publish post_type: post

eldapo does php

Been experimenting with PHP for a few days — finally. My friend Gary Utz was after me a couple of years ago to do this, and I even bought a couple of O’Reilly books on it.

Well, here I am. Of course, rather than do something simple like write a MySQL database app, I’m working on a simple LDAP white pages lookup thing.

Here’s my code “sandbox”, a little script I’ll be adding and removing from until I get something decent. Right now it just searches for an entry and prints out some info.

[code language="php"]LDAP query test"; echo "Connecting ..."; $dirHost = "ldap.example.com"; $usrbase = "dc=example,dc=com"; $query = "title=IT Systems Analyst"; $ds=ldap_connect($dirHost); // must be a valid LDAP server! echo "connect result is " . $ds . "
"; if ($ds) { echo "Binding ..."; $r=ldap_bind($ds); // this is an "anonymous" bind, typically // read-only access echo "Bind result is " . $r . "
"; echo "Searching for (sn=S*) ..."; // Search surname entry $sr=ldap_search($ds, $usrbase, $query); echo "Search result is " . $sr . "
"; echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "
"; echo "Getting entries ...

"; $info = ldap_get_entries($ds, $sr); echo "Data for " . $info["count"] . " items returned:

"; for ($i=0; $i<$info["count"]; $i++) { echo "dn is: " . $info[$i]["dn"] . "
"; echo "first cn entry is: " . $info[$i]["cn"][0] . "
"; echo "first email entry is: " . $info[$i]["mail"][0] . "


"; } echo "Closing connection"; ldap_close($ds); } else { echo "

Unable to connect to LDAP server

"; } ?> [/code]

My first impression is that Perl’s Net::LDAP module, which has been the mainstay of my daily activities for almost 7 years, is easier to work with. Of course, I’ve been writing scripts in Perl so long that its syntax has become second nature. PHP generally reminds me of Javascript or VBScript more than anything else. One thing I’m going to be interested in finding out is how you’d do a Simple Paged Results search using php-ldap (if it can be done at all), which is critical to working with Active Directory over the LDAP protocol.

Copyright 2004-2019 Phil Lembo

⚠️ **GitHub.com Fallback** ⚠️