Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

PHP and Active Directory

 
   Database Forums (Home) -> PHP RSS
Next:  PHP and Active Directory  
Author Message
andyt_2000_uk

External


Since: Nov 27, 2005
Posts: 5



(Msg. 1) Posted: Sun Nov 27, 2005 4:36 pm
Post subject: PHP and Active Directory
Archived from groups: comp>lang>php (more info?)

Hi

I'm trying to get it so visitors to our intranet site are able to log
into the site with there normal login details. On a network using
win2k3, active directory etc.

Now my code at the moment seems to connect to AD but it fails when it
trys to bind.

<?php
//Connect to Active Directory
$ad = ldap_connect("hole.chase.local, 389") or
die("Couldn't connect to AD!"."<br />");
echo "connect result is " . $ad . "<br />";

//set protocol version
if (ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) {
echo "Using LDAPv3". "<br />";
} else {
echo "Failed to set protocol version to 3";
}

$ldaprdn = 'andy';
$ldappass = 'password';

//Bind to Active Directory
if ($ad){
$bd = ldap_bind($ad, $ldaprdn, $ldappass) or
die("Couldn't bind to AD!");
}
if ($bd){
echo "success"."<br />";
} else {
echo "fail"."<br />";
}
?>

Everytime it runs it dies, saying Couldn't bind to AD!

Checking the logs for apache i notice it reports

[client 127.0.0.1] PHP Warning: ldap_bind(): Unable to bind to
server: Can't contact LDAP server in F:\\Website\\htdocs\\example3.php
on line 23

Any ideas on how to solve this would be great.

Cheers

Andy

 >> Stay informed about: PHP and Active Directory 
Back to top
Login to vote
user3152

External


Since: Jan 18, 2005
Posts: 90



(Msg. 2) Posted: Sun Nov 27, 2005 6:08 pm
Post subject: Re: PHP and Active Directory [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

andyt_2000_uk.DeleteThis@yahoo.co.uk wrote:
>
> I'm trying to get it so visitors to our intranet site are able to log
> into the site with there normal login details. On a network using
> win2k3, active directory etc.
>
> Now my code at the moment seems to connect to AD but it fails
> when it trys to bind.

Of course it does... Consider a few changes to your code:

//Connect to Active Directory
$ad = ldap_connect('hole.chase.local', 389)
// First change ^^^^^^^^^^^^^^^^^^^^^^^
or die("Couldn't connect to AD!"."<br />");
echo "connect result is " . $ad . "<br />";
//set protocol version
if (ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3)) {
// Second change ^^
echo "Using LDAPv3". "<br />";
} else {
echo "Failed to set protocol version to 3";
}
$ldaprdn = 'andy';
$ldappass = 'password';
//Bind to Active Directory
if ($ad) {
$bd = ldap_bind($ad, $ldaprdn, $ldappass)
or die("Couldn't bind to AD!");
}
if ($bd) {
echo "success"."<br />";
} else {
echo "fail"."<br />";
}

Cheers,
NC

 >> Stay informed about: PHP and Active Directory 
Back to top
Login to vote
andyt_2000_uk

External


Since: Nov 27, 2005
Posts: 5



(Msg. 3) Posted: Mon Nov 28, 2005 2:43 am
Post subject: Re: PHP and Active Directory [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Cheers, didn't spot those 2 mistakes.

Unfortunately i still get the same errors of not being able to bind to
AD.
 >> Stay informed about: PHP and Active Directory 
Back to top
Login to vote
David Wahler

External


Since: Nov 28, 2005
Posts: 1



(Msg. 4) Posted: Mon Nov 28, 2005 5:08 am
Post subject: Re: PHP and Active Directory [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

andyt_2000_uk.TakeThisOut@yahoo.co.uk wrote:
> Unfortunately i still get the same errors of not being able to bind to
> AD.

Try changing:
die("Couldn't bind to AD!");
to:
die("Couldn't bind to AD: " . ldap_error($ad));

As it is, you're suppressing all the useful information that might help
you solve the problem.

-- David
 >> Stay informed about: PHP and Active Directory 
Back to top
Login to vote
Uchi

External


Since: Nov 24, 2005
Posts: 2



(Msg. 5) Posted: Mon Nov 28, 2005 8:44 pm
Post subject: Re: PHP and Active Directory [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

May be your server name is not correct
try using

$ds = ldap_server("localhost");

or

$ds = ldap_server("ldap://localhost");

if you are doing it on the server it self otherwise look for the
correct name that could be the problem as well....

Uchi
 >> Stay informed about: PHP and Active Directory 
Back to top
Login to vote
andyt_2000_uk

External


Since: Nov 27, 2005
Posts: 5



(Msg. 6) Posted: Wed Nov 30, 2005 2:50 am
Post subject: Re: PHP and Active Directory [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Cheers all for the help, it appears there was a DNS issue on the 2k3
box and so the ldap server name wasn't getting resolved.

Cheers
 >> Stay informed about: PHP and Active Directory 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Active directory and PHP - Is there anyway to work PHP with Active directory? My intention consist in developing an application that authenticates automatically PHP on W2k3 server. tks, Marcos

Hidden directory - Hi everyone, I'm running php on win2000 server and iis. I have a script that builds the directory sturcture of a directory or a drive. My problem is that i want to find that which directories are hidden. I have looked stat() function but it seems that i...

Directory security - I'm building a site on a 3rd party server which runs Unix, Apache, php and mySQL I have a number of sub directories containing only acrobat pdf files and some other directories with php files (but no index.htm) If I type the website url and then the....

PHP Scripts to run in another directory with IIS - I would like to have PHP for windows run in another directory than c:\inetpub\wwwroot. I have tride changeing parameters in php.ini in my c:\php directory. But nothing changes. When I run the phpinfo() I always get Configuration File (php.ini) Path as...

Subdirectory ain't directory - Hi. I am writing a function that takes a given path and displays subdirectories and files with proper description: "file" or "directory". I have written the following code: function list_dir($dir) { if (!is_dir($dir)) { ...
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]