FAQ
<?php
set_time_limit(30);
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);

// config
$ldapserver = 'svr.domain.com';
$ldapuser = 'administrator';
$ldappass = 'PASSWORD_HERE';
$ldaptree = "OU=SBSUsers,OU=Users,OU=MyBusiness,DC=myDomain,DC=local";

// connect
$ldapconn = ldap_connect($ldapserver) or die("Could not connect to LDAP server.");

if($ldapconn) {
     // binding to ldap server
     $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass) or die ("Error trying to bind: ".ldap_error($ldapconn));
     // verify binding
     if ($ldapbind) {
         echo "LDAP bind successful...<br /><br />";


         $result = ldap_search($ldapconn,$ldaptree, "(cn=*)") or die ("Error in search query: ".ldap_error($ldapconn));
         $data = ldap_get_entries($ldapconn, $result);

         // SHOW ALL DATA
         echo '<h1>Dump all data</h1><pre>';
         print_r($data);
         echo '</pre>';


         // iterate over array and print data for each entry
         echo '<h1>Show me the users</h1>';
         for ($i=0; $i<$data["count"]; $i++) {
             //echo "dn is: ". $data[$i]["dn"] ."<br />";
             echo "User: ". $data[$i]["cn"][0] ."<br />";
             if(isset($data[$i]["mail"][0])) {
                 echo "Email: ". $data[$i]["mail"][0] ."<br /><br />";
             } else {
                 echo "Email: None<br /><br />";
             }
         }
         // print number of entries found
         echo "Number of entries found: " . ldap_count_entries($ldapconn, $result);
     } else {
         echo "LDAP bind failed...";
     }

}

// all done? clean up
ldap_close($ldapconn);
?>
----
Server IP: 69.147.83.199
Probable Submitter: 65.198.62.100
----
Manual Page -- http://php.net/manual/en/function.ldap-search.php
Edit -- https://master.php.net/note/edit/112191
Del: integrated -- https://master.php.net/note/delete/112191/integrated
Del: useless -- https://master.php.net/note/delete/112191/useless
Del: bad code -- https://master.php.net/note/delete/112191/bad+code
Del: spam -- https://master.php.net/note/delete/112191/spam
Del: non-english -- https://master.php.net/note/delete/112191/non-english
Del: in docs -- https://master.php.net/note/delete/112191/in+docs
Del: other reasons-- https://master.php.net/note/delete/112191
Reject -- https://master.php.net/note/reject/112191
Search -- https://master.php.net/manage/user-notes.php

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-notes @
categoriesphp
postedMay 15, '13 at 6:28p
activeMay 15, '13 at 6:28p
posts1
users1
websitephp.net

1 user in discussion

Jayleno: 1 post

People

Translate

site design / logo © 2019 Grokbase