There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: PHP and AD


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
kratak's Avatar
Senior Member with 116 posts.
 
Join Date: Jan 2005
Experience: Advanced
07-Dec-2005, 06:43 AM #1
Solved: PHP and AD
Hi,

Im trying to use PHP to connect to AD, essentially on the Intranet i want the login page to authenticate through AD rather than going through our SQL server database.

Im running PHP 5.1.2 on Apache 2.0.55 and MS server2000

Im ok at binding to the server, its just when i try and search i get the following error.

Warning: ldap_search() [function.ldap-search]: Search: Operations error in c:\web\index2.php on line 25

Warning: ldap_get_entries(): supplied argument is not a valid ldap link resource in c:\web\index2.php on line 27
entries returned
<?php


$ad = ldap_connect("RPMAIL") or
die("Couldn't connect to AD!");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);

$ldaprdn = 'user';
$ldappass = 'password';

$ldapbind = ldap_bind($ad, $ldaprdn, $ldappass);

if ($ldapbind) {
echo "LDAP bind successful...";
} else {
echo "LDAP bind failed...";
}


$dn = "o=My Company, c=US";
$filter="(|(sn=$person*)(givenname=$person*))";
$justthese = array("ou", "sn", "givenname", "mail");

$sr=ldap_search($ds, $dn, $filter, $justthese);

$info = ldap_get_entries($ds, $sr);

echo $info["count"]." entries returned\n";

?>

thanks
Gibble's Avatar
Distinguished Member with 27,137 posts.
 
Join Date: Oct 2001
Location: Striking or Scoring
Experience: The Alpha and Omega
07-Dec-2005, 12:07 PM #2
The error you have to fix is the ldap_search() one. The ldap_get_entries() error is caused because of it's failure.

Well, you connect and store the resource as $ad, yet when you do the ldap_search you are trying to use the resource $ds...which I don't see you setting anywhere, try using the $ad resource instead.
__________________
izme: You know...it's kind of nice to sit atop Civilized debate and look down below on all of the uncivilized master debating we are here...just out of the fight zone

Gibble: Now you know what it's like to be Canadian.
kratak's Avatar
Senior Member with 116 posts.
 
Join Date: Jan 2005
Experience: Advanced
08-Dec-2005, 08:06 AM #3
Hi

Thanks, I tried that and i get the same error.
Gibble's Avatar
Distinguished Member with 27,137 posts.
 
Join Date: Oct 2001
Location: Striking or Scoring
Experience: The Alpha and Omega
08-Dec-2005, 09:24 AM #4
Well, you also don't set $person anywhere, and I think you should change your organization and country parameters in the following line to what they are in your Active Directory setup.

$dn = "o=My Company, c=US";
kratak's Avatar
Senior Member with 116 posts.
 
Join Date: Jan 2005
Experience: Advanced
09-Dec-2005, 06:05 AM #5
Hi,

I did some searching and found another example. I figured go for the basic first. However all i get in the display is "LDAP bind successful..." Do you know what the dc=com section is, i dont understand that bit. Is it somehting to do with base_dn?

<?php

$ad = ldap_connect("RPMAIL") or
die("Couldn't connect to AD!");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);

$ldaprdn = 'user';
$ldappass = 'password';

$ldapbind = ldap_bind($ad, $ldaprdn, $ldappass);

if ($ldapbind) {
echo "LDAP bind successful...";
} else {
echo "LDAP bind failed...";
}

$dn = "dc=com";
$attributes = array("displayname", "l");
$filter = "(sn=M*)";


$result = ldap_search($ad, $dn, $filter, $attributes);

$entries = ldap_get_entries($ad, $result);

for ($i=0; $i<$entries["count"]; $i++)
{
echo $entries[$i]["displayname"]
[0]."(".$entries[$i]["l"][0].")<br />";
}

ldap_unbind($ad);
?>
Gibble's Avatar
Distinguished Member with 27,137 posts.
 
Join Date: Oct 2001
Location: Striking or Scoring
Experience: The Alpha and Omega
09-Dec-2005, 09:34 AM #6
let's remove the base.

Change $dn to an empty string
$dn = ""

Then check your ldap.conf file and make sure that no BASE is set. so if you see a line that looks similar to this, make sure it has a # in the beginning, if it doesn't, add it.
#BASE dc=example, dc=com
__________________
izme: You know...it's kind of nice to sit atop Civilized debate and look down below on all of the uncivilized master debating we are here...just out of the fight zone

Gibble: Now you know what it's like to be Canadian.
kratak's Avatar
Senior Member with 116 posts.
 
Join Date: Jan 2005
Experience: Advanced
12-Dec-2005, 05:22 AM #7
Hi

just want to say thankyou for all of your help. I've got it working by setting the base to local and not com.

thanks again,
Kev

I do have another litte query now. (Sorry to keep asking questions) I was curious why when trying to bind to AD it uses the display name rather than the NT login username. Also is it possible to use the NT login rather than the display name?

Last edited by kratak : 12-Dec-2005 09:10 AM.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:06 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.