Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-03-2006, 08:01 PM   #1
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Rep: Reputation: 30
php connect "active directory" script

hi there,

i'm just wondering if someone out there has writtern a basic php script that will connect to active directory using ldap? and maybe search it?

i'm looking for maybe a combination of this

and this

if ($name_submitted != "" && $passwd_submitted != "") {

$ldap_host = "ldap://";
$base_dn = "CN=Users,DC=rhodes, DC=edu";

if ($search_submitted == "") {
$search_value = $name_submitted;
} else {
$search_value = $search_submitted;

$filter = "(CN=$search_value)";
$ldap_user = "CN=$name_submitted, CN=Users, DC=rhodes, DC=edu";
$ldap_pass = $passwd_submitted;

$connect = ldap_connect( $ldap_host, $ldap_port)
or exit("Could not connect to LDAP server");

// required to search AD, according to note in PHP manual notes
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);

$bind = ldap_bind($connect, $ldap_user, $ldap_pass)
or exit("Could not bind to $ldap_host");

echo "Successful bind to $ldap_host with $bind<br><br>\n";

$read = ldap_search($connect, $base_dn, $filter)
or exit("Unable to search ldap server");

$info = ldap_get_entries($connect, $read);
echo $info["count"]." entries returned for $filter<br><br>\n";

for ($i=0; $ii<$info[$i]["count"]; $ii++){
$data = $info[$i][$ii];
if ($data == "memberof") {
$total_memberof = (count($info[$i][$data]));
echo "Total memberof entries returned: $total_memberof<br><br>\n";
$total = 0;
$total = count($info[$i][$data]);
for ($jj=0; $jj<$total; $jj++) {
if ($info[$i][$data][$jj] == "CN=STAFF,OU=Security
Groups,OU=Groups,DC=rhodes,DC=edu") {
echo "<b>Got Staff Match</b> ";
$user_type = "staff";
} elseif (($info[$i][$data][$jj] == "CN=FACULTY,OU=Security
Groups,OU=Groups,DC=rhodes,DC=edu") && $user_type == "") {
echo "<b>Got Faculty Match</b> ";
$user_type = "faculty";
} elseif (($info[$i][$data][$jj] == "CN=Students,OU=Security
Groups,OU=Groups,DC=rhodes,DC=edu") && $user_type == "") {
echo "<b>Got Students Match</b> ";
$user_type = "student";
echo $i." ".$ii." ".$jj."



echo "<br><br><b>User Type is: ";

switch ($user_type) {
case "staff":
echo "STAFF";
case "faculty":
echo "FACULTY";
case "student":
echo "STUDENT";
echo "UNKNOWN";

echo "</b><br><br>\n";

echo "<br><br><a href=\"index.php\">Search again</a><br><br>\n";

} else {

echo "<html><head></head><body>\n";
echo "<form action=\"index.php\" method=\"POST\">\n";
echo "AD User Name: <input type=\"text\"
echo "AD Password: <input type=\"password\"
echo "Search User Name: <input type=\"text\"
echo "<input type=\"submit\" value=\"Submit\">\n";
echo "</form>\n";
echo "</body></html>\n";


so I want a username/password inside the file that connects to the Active Directory server and then I just want a search box that i can search the displayName area and return with mail area.

Last edited by paul_mat; 05-03-2006 at 08:19 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Squid + Active Directory "squid_ldap_auth " RedCamel Linux - Software 1 12-24-2007 04:01 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM
cgi-bin: "attempt to invoke directory as script" hamish Linux - Software 0 12-09-2004 12:45 PM
Authenticating to Samba share using "Active Directory Server" hlslaughter Linux - Software 36 07-23-2004 10:59 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:32 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration