note 72526 added to function.ldap-search

From: Date: Tue, 23 Jan 2007 10:18:50 +0000
Subject: note 72526 added to function.ldap-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-122057@lists.php.net to get a copy of this message
I was completely lost trying to setup LDAP access with a Windows Server 2003 environment, but I finally got it to work. Here's a lifesaving tip: -Script/web server cannot be located on the Active Directory server that you are querying As well, here's the sample code I used: <?php //This code cannot be executed on the same server as AD is installed on!!! //Connect $ad = ldap_connect("ad server"); //Set some variables ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ad, LDAP_OPT_REFERRALS, 0); //Bind to the ldap directory $bd = ldap_bind($ad,"user@domain.com","password") or die("Couldn't bind to AD!"); //Search the directory $result = ldap_search($ad, "OU=orginizational unit,DC=domain,DC=com", "(CN=*)"); //Create result set $entries = ldap_get_entries($ad, $result); //Sort and print echo "User count: " . $entries["count"] . "<br /><br /><b>Users:</b><br />"; for ($i=0; $i < $entries["count"]; $i++) { echo $entries[$i]["displayname"][0]."<br />"; } //never forget to unbind! ldap_unbind($ad); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 71.165.197.213 ---- Manual Page -- http://www.php.net/manual/en/function.ldap-search.php Edit -- https://master.php.net/note/edit/72526 Del: integrated -- https://master.php.net/note/delete/72526/integrated Del: useless -- https://master.php.net/note/delete/72526/useless Del: bad code -- https://master.php.net/note/delete/72526/bad+code Del: spam -- https://master.php.net/note/delete/72526/spam Del: non-english -- https://master.php.net/note/delete/72526/non-english Del: in docs -- https://master.php.net/note/delete/72526/in+docs Del: other reasons-- https://master.php.net/note/delete/72526 Reject -- https://master.php.net/note/reject/72526 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122057) next »