[PHP-DOC] #15637 [Com]: if using URI, ldap_connect() returns resource ID when server does not exist From: f.labanvoye <email protected>
Date: 11/29/02

 ID: 15637
 Comment by: f.labanvoye <email protected>
 Reported By: cjm46543 <email protected>
 Status: Verified (bughun
 Bug Type: Documentation problem
 Operating System: Linux - RedHat 7.2
 PHP Version: 4.3.0-dev
 New Comment:

Hello,

in php-4.30rcX, the ldap_connect doesn't perform the connection, so
documentation should be updated.
But, the documention (on zend site) for ldap_connect is:

ldap_connect() establishes a connection to a LDAP server on a
specified
hostname and port. Both the arguments are optional. --> If no
arguments
are specified then the link identifier of the already opened link will
be returned.

In my script i don't have any previous opened link, so i think the
function would return FALSE.
Or the documention is wrong and need correction.

<?php

$ds = ldap_connect ( );
echo $ds // return a valid ldap resource

?>

Sincerely

Previous Comments:
------------------------------------------------------------------------

[2002-10-31 15:09:44] rattray <email protected>

mfischer <email protected> suggests that "Checking the return code of ldap_bind()
would be the proper thing to do anyway." However, the act of calling
ldap_bind generates an error message on the page, e.g.:

"Warning: LDAP: Unable to bind to server: Can't contact LDAP server in
/home/shop/www/ldaps-1.php on line 8"

before any check can be made on the results of ldap_bind().
We are trying to create our first secure ldap system, and the
false-positive returns from ldap_connect() are making it difficult to
track down problems.

------------------------------------------------------------------------

[2002-07-02 11:19:51] eru <email protected>

Reverified during bughunt. From the user-comments:

"When using an URI to describe the connection, the (open)ldap library
only parses the url and checks if it's valid, _no connection_ is
established in that case."
-mfischer <email protected>

------------------------------------------------------------------------

[2002-02-20 05:20:14] mfischer <email protected>

This is not an PHP/ldap bug but a documentation problem it seems to
me.

When using an URI to describe the connection, the (open)ldap library
only parses the url and checks if it's valid, _no connection_ is
established in that case.

Checking the return code of ldap_bind() would be the proper thing to do
anyway.

------------------------------------------------------------------------

[2002-02-19 20:05:48] cjm46543 <email protected>

I'm running a very simple test script (see below) to test my ldap
server connection. According to the docs, ldap_connect() is supposed
to return an LDAP resource id on successful connect, or FALSE on error.
 When I run the code with a valid server URI ($ds =
ldap_connect("ldap://ldap.example.com")), everything works fine. When
I run it with a URI to a nonexistent LDAP server ($ds =
ldap_connect("ldap://does.not.exist")), ldap_connect returns a resource
ID anyway, so my script has no way of knowing anything is wrong until I
try to bind or search. If I simply give a nonexistent hostname rather
than a URI ($ds = ldap_connect("does.not.exist")) the function returns
FALSE as documented.

I built PHP 4.1.1 against the client libraries from OpenLDAP 2.0.21.
Here's the full code of my test script:

<?php
$ds = ldap_connect("ldap://ldap.example.com/");
echo "connect result is ".$ds."<p>";
if($ds) {
  $r=ldap_bind($ds);
  echo "Bind result is ".$r."<p>";
  $sr=ldap_search($ds, "ou=users,dc=example,dc=com", "uid=carljm");
  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>";
  for ($i=0; $i<$info["count"]; $i++) {
    echo "dn is: ". $info[$i]["dn"] ."<br>";
    echo "first cn entry is: ". $info[$i]["cn"][0] ."<br>";
    echo "first uidNumber entry is: ". $info[$i]["uidnumber"][0]
."<p>";
    }
echo "Closing connection";
ldap_close($ds);
?>
 

------------------------------------------------------------------------

-- 
Edit this bug report at http://bugs.php.net/?id=15637&edit=1

-- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php