|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-02-19 20:05 UTC] cjm46543 at hotmail dot com
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);
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 11:00:02 2025 UTC |
I have observed something like this (in php-4.30rc3): The whole script: <? $ldaphost = "nonexistendserver"; $ldapport = 389; $ldapconn = ldap_connect( $ldaphost, $ldapport ) or die( "Could not connect to {$ldaphost}" ); echo $ldapconn; // display a valid ldap resource ?> regards.when using an ip address ldap_connect doesn't work as described. $server = "10.1.1.100"; $port = "389"; $ds = ldap_connect($server, $port); the result is true even if the server does not exist or the service is not running.I cannot get ldap_connect() to return false under ANY conditions, including with the examples provided in this bug report. I find this behavior impossible to document, please have another look at this. Reclassifying -> ldap related. Shouldn't these return false? They are not URI's: var_dump(ldap_connect('foo')); var_dump(ldap_connect('does.not.exist')); I get resources with both. apache1.3.26/php4.4/openldap2.0.23This is not just a documentation problem. Not only does $ldap_connection = ldap_connect("does.not.exist") return a resource id when it obviously shouldn't, but ldap_bind($ldap_connection, 'username', 'password') also returns true. If the actual connect occurs with ldap_bind(), why does it return true for a server that does not exist? Regards.My solution was to go one step further by using 'ldap_bind' to test the connection : $ds=ldap_connect("titi.tata.net"); $r=@ldap_bind($ds,"cn=toto","tutu"); if ($r) { bla bla bla } else die("LDAP server not accessed !"); The '@' before 'ldap_bind' disables Warning dysplay.