ldap_bind problem

This is a discussion on ldap_bind problem within the PHP Language forums, part of the PHP Programming Forums category; Hi, I have a basic script for querying an ldap server. It works fine from my college's production server, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-23-2006
downlode@gmail.com
 
Posts: n/a
Default ldap_bind problem

Hi,
I have a basic script for querying an ldap server. It works fine from
my college's production server, but not from another server in the
network, though I have been assured access should be allowed from
there.

It fails at the ldap_bind() function. This function only returns a
boolean value. How might I retrieve a meaninful error message? Any
ideas where the problem is likely to lie, with this basic info?

Here is the code.

//----------------------------------------------------------------
$myclient="usernamehere";
echo "<h3>LDAP query test</h3>";
echo "<B>Connecting ...</B><BR>";

$ds=ldap_connect("xxxxx.xxxxx.ac.uk"); // working address supplied
here...
echo "connect result is ".$ds."<p>";

if ($ds) {
echo "Binding ...(anon)...";
$r=ldap_bind($ds);
echo "Bind result is ".$r."<p>";

echo "Searching for <B>$myclient</B> ...";
// Search surname entry
$sr=ldap_search($ds,"OU=STAFF, OU=DS, OU=SEC, O=LINST",
"CN=$myclient");
echo "Search result is ".$sr."<p>";

echo "Number of entires returned is
".ldap_count_entries($ds,$sr)."<p>";

echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for ".$info["count"]." items returned:<p>";
echo "<HR>";

for ($i=0; $i<$info["count"]; $i++) {
echo "Full name (fullname) entry is: ".
$info[$i]["fullname"][0] ."<br>";
echo "Job title (title) entry is: ". $info[$i]["title"][0]
.."<br>";
echo "Common name (cn) entry is: ". $info[$i]["cn"][0]
.."<br>";
echo "E-mail (mail) entry is: ". $info[$i]["mail"][0] ."<br>";
echo "Telephone (telephonenumber) entry is: ".
$info[$i]["telephonenumber"][0]."<br>";
echo "Domain (dn) is: ". $info[$i]["dn"] ."<P><HR>\n";

echo printall($info[$i]);

}

echo "<P><B>Closing connection</B>";
ldap_close($ds);

} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
//----------------------------------------------------------------

Any suggestions welcome.
Mike

Reply With Quote
  #2 (permalink)  
Old 05-23-2006
ZeldorBlat
 
Posts: n/a
Default Re: ldap_bind problem


downlode@gmail.com wrote:
> Hi,
> I have a basic script for querying an ldap server. It works fine from
> my college's production server, but not from another server in the
> network, though I have been assured access should be allowed from
> there.
>
> It fails at the ldap_bind() function. This function only returns a
> boolean value. How might I retrieve a meaninful error message? Any
> ideas where the problem is likely to lie, with this basic info?
>
> Here is the code.
>
> //----------------------------------------------------------------
> $myclient="usernamehere";
> echo "<h3>LDAP query test</h3>";
> echo "<B>Connecting ...</B><BR>";
>
> $ds=ldap_connect("xxxxx.xxxxx.ac.uk"); // working address supplied
> here...
> echo "connect result is ".$ds."<p>";
>
> if ($ds) {
> echo "Binding ...(anon)...";
> $r=ldap_bind($ds);
> echo "Bind result is ".$r."<p>";
>
> echo "Searching for <B>$myclient</B> ...";
> // Search surname entry
> $sr=ldap_search($ds,"OU=STAFF, OU=DS, OU=SEC, O=LINST",
> "CN=$myclient");
> echo "Search result is ".$sr."<p>";
>
> echo "Number of entires returned is
> ".ldap_count_entries($ds,$sr)."<p>";
>
> echo "Getting entries ...<p>";
> $info = ldap_get_entries($ds, $sr);
> echo "Data for ".$info["count"]." items returned:<p>";
> echo "<HR>";
>
> for ($i=0; $i<$info["count"]; $i++) {
> echo "Full name (fullname) entry is: ".
> $info[$i]["fullname"][0] ."<br>";
> echo "Job title (title) entry is: ". $info[$i]["title"][0]
> ."<br>";
> echo "Common name (cn) entry is: ". $info[$i]["cn"][0]
> ."<br>";
> echo "E-mail (mail) entry is: ". $info[$i]["mail"][0] ."<br>";
> echo "Telephone (telephonenumber) entry is: ".
> $info[$i]["telephonenumber"][0]."<br>";
> echo "Domain (dn) is: ". $info[$i]["dn"] ."<P><HR>\n";
>
> echo printall($info[$i]);
>
> }
>
> echo "<P><B>Closing connection</B>";
> ldap_close($ds);
>
> } else {
> echo "<h4>Unable to connect to LDAP server</h4>";
> }
> //----------------------------------------------------------------
>
> Any suggestions welcome.
> Mike


You can get the error or error number of the last command executed with
ldap_error() and ldap_errno(). See the following:

<http://www.php.net/ldap_error>
<http://www.php.net/ldap_errorno>

Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:10 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0