LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 08-03-2006, 12:21 AM   #1
paul_mat
Member
 
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,

What i'm trying to do is setup a php page to connect to my Active directory server and output all the sAMAccountnames into a drop down box. this is what I have so far.

Code:
<select size="1" name="adsusers">
<?php

$ldap_server = "ldap://senior-server.mydomain.com";
$auth_user = "moodleuser@mydomain.com";
$auth_pass = "Moodle";

$base_dn = "OU=All Staff,DC=Mydomain,DC=com";

$filter = "(objectClass=person)";

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

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

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);

for ($i=0; $i<$info["count"]; $i++) {

echo "<option>". $info[$i]["sAMAccountName"][0]."</option>";

}

ldap_close($connect);
?>

</select>
The only problem seams to be this line.

echo "<option>". $info[$i]["sAMAccountName"][0]."</option>";

when i run tail /var/log/httpd/error_log

[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
[Thu Aug 03 15:14:26 2006] [error] [client 192.168.0.254] PHP Notice: Undefined index: sAMAccountName in /var/www/html/ldap/ads.php on line 30
 
Old 08-03-2006, 01:01 AM   #2
ckin2001
LQ Newbie
 
Registered: Jul 2006
Location: Chambana
Distribution: debian
Posts: 17

Rep: Reputation: 0
I thought it was SAMAccountName? Typo?
 
Old 08-03-2006, 01:06 AM   #3
paul_mat
Member
 
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Original Poster
Rep: Reputation: 30
well I tried, SAMAccountName and no luck, still isn't working.

But if i put in sn or mail, it all seams to work .... :s i'm confused ... But at the same time if i put in displayName it dosn't work.

Any idea's?
 
Old 08-03-2006, 03:24 AM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Life is too weird sometimes... I just finished working on a PHP/AD script to do something similar.

In my script, I use 'samaccountname' as the index, all lower case. If you want to be sure though, just add this to your script and examine the output:

Code:
foreach ($info[$i] as $k => $v) {
    echo "Key is ".$k;
}
 
  


Reply


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
php connect "active directory" script paul_mat Linux - Software 0 05-03-2006 08:01 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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:13 AM.

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