473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PHP and Active Directory

Hi all,

Via a PHP script (running on a LAMP configuration - PHP with LDAP
support), I run queries on the LDAP server of our office (users and
arguments). Now, I want to put the result of this query (user
information) in a Windows 2003 AD.
I use PHP-ldap functions to connect with the domain controller: making
connection is no problem, but binding (authenticated, I even tried
Domain Administrator credentials) doesn't work...
Does anyone has experience with this matter (PHP and AD
connection/communucation)?

Thanks in advance!

Zeff.
Sep 15 '05 #1
2 3302
Zeff wrote:
Hi all,

Via a PHP script (running on a LAMP configuration - PHP with LDAP
support), I run queries on the LDAP server of our office (users and
arguments). Now, I want to put the result of this query (user
information) in a Windows 2003 AD.
I use PHP-ldap functions to connect with the domain controller: making
connection is no problem, but binding (authenticated, I even tried
Domain Administrator credentials) doesn't work...
Does anyone has experience with this matter (PHP and AD
connection/communucation)?

Thanks in advance!

Zeff.


I've done a bit of this, it can be a bit brain busting. Does something
like this work? (This should bind to the AD an search for the DN of
JoeUser)

$ldap_def_user = "cn=ldapquery,ou=Users,dc=yourcompany,dc=com";
$ldap_def_pass = "password";
$ldap_server = "server.yourcompany.com";
$ldap_base_dn = "ou=Users,dc=yourcompany,dc=com";

$Connect = ldap_connect($ldap_server) ;
$Bind = ldap_bind($Connect,$ldap_def_user,$ldap_def_pass) ;

if( !$Bind) die "Unable to bind to directory";

$UserName=JoeUser;
$ld_filter = '(sAMAccountName=' . $UserName . ')';
$ld_data = array('dn');
$ld_sr = ldap_search($Connect, $ldap_base_dn, $ld_filter, $ld_data);
$ld_info = ldap_get_entries($ld_connect, $ld_sr);

$ld_count = $ld_info['count'];
if ( $ld_count < 1) die "User doesn't exist";
$ldap_user_dn = $ld_info[0]['dn'];

print("UserName is $ldap_user_dn");

I did have some success with using

ldap_bin("ldaps://us******@server.yourcompany.com") but have lost my
notes on that.

One thing to watch is when you're dealing with the unique identifier of
an object, the GUID. It's specified as a 128 bit octet string, but they
allow NULLS. (What idiot allows a NULL inside a string???) You have to
use binary ldap fetches and convert it into a hex string.

Good luck :-)

Sacs
Sep 15 '05 #2
Replying to myself, bad form I know, but bug in my code (I had taken it
from some notes, not actual working code...)

<?php
$ldap_def_user = "cn=ldapquery,ou=Users,dc=yourcompany,dc=com";
$ldap_def_pass = "password";
$ldap_server = "server.yourcompany.com";
$ldap_base_dn = "ou=Users,dc=yourcompany,dc=com";

$Connect = ldap_connect($ldap_server) or die("Could not connect") ;
$Bind = ldap_bind($Connect,$ldap_def_user,$ldap_def_pass) or die("Could
not bind");
$UserName=JoeUser;
$ld_filter = '(sAMAccountName=' . $UserName . ')';
$ld_data = array('dn');
$ld_sr = ldap_search($Connect, $ldap_base_dn, $ld_filter, $ld_data);
$ld_info = ldap_get_entries($Connect, $ld_sr);

$ld_count = $ld_info['count'];
if ( $ld_count < 1) {
print("User $UserName doesn't exist");
} else {
$ldap_user_dn = $ld_info[0]['dn'];
print("$UserName DN is $ldap_user_dn");
}
?>
Sep 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jay Chan | last post by:
We have just installed a SQL Server 2000 (SP 3A) onto a computer that has Windows-2003 Server on it. Now, we cannot get access to that database server from other computers. Seem like this may be an...
0
by: microsoft | last post by:
Hi People, when I try to modify an active directory user programatically, I receive the following exception: The server is unwilling to process the request Reading the microsoft web site, I...
9
by: Mario Rodriguez | last post by:
Hi people. I have a problem adding users to Win2003 active directory programatically. When I execute my app throws the following exception: .................The specified directory service...
4
by: ASGMikeG | last post by:
Hi, How do I find the user object for the current user in Active Directory i.e. the user running my program ? Regards Michael
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
6
by: Leo_Surf | last post by:
Hello, I need your help adding user in Active Directory from ASP.net website. Could any one provide me the complete code for the html page. As this is my curriculam project and I dont have any...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
10
by: Hriday | last post by:
Hi there, Please help me..It is urgent This is Hriday, working on windows authentication with Active Directory... My requirment is when a user sends a request to my web Applicatoin I want to...
0
by: RTT | last post by:
here is my current situation. I develop a program on my computer's localhost. From there i contact Active directory succesfull using a connectionstring like:...
2
by: Jim in Arizona | last post by:
My goal, somehow, is to populate a dropdownlist with all the user names in active directory. I don't even know where to begin, really. I added a reference to System.DirectoryServices so I could...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.