ldap_bind problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • downlode@gmail.com

    #1

    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="user namehere";
    echo "<h3>LDAP query test</h3>";
    echo "<B>Connect ing ...</B><BR>";

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

    if ($ds) {
    echo "Binding ...(anon)...";
    $r=ldap_bind($d s);
    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_en tries($ds,$sr). "<p>";

    echo "Getting entries ...<p>";
    $info = ldap_get_entrie s($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 (telephonenumbe r) entry is: ".
    $info[$i]["telephonenumbe r"][0]."<br>";
    echo "Domain (dn) is: ". $info[$i]["dn"] ."<P><HR>\n" ;

    echo printall($info[$i]);

    }

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

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

    Any suggestions welcome.
    Mike

  • ZeldorBlat

    #2
    Re: ldap_bind problem


    downlode@gmail. com wrote:[color=blue]
    > 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="user namehere";
    > echo "<h3>LDAP query test</h3>";
    > echo "<B>Connect ing ...</B><BR>";
    >
    > $ds=ldap_connec t("xxxxx.xxxxx. ac.uk"); // working address supplied
    > here...
    > echo "connect result is ".$ds."<p>" ;
    >
    > if ($ds) {
    > echo "Binding ...(anon)...";
    > $r=ldap_bind($d s);
    > 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_en tries($ds,$sr). "<p>";
    >
    > echo "Getting entries ...<p>";
    > $info = ldap_get_entrie s($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 (telephonenumbe r) entry is: ".
    > $info[$i]["telephonenumbe r"][0]."<br>";
    > echo "Domain (dn) is: ". $info[$i]["dn"] ."<P><HR>\n" ;
    >
    > echo printall($info[$i]);
    >
    > }
    >
    > echo "<P><B>Clos ing connection</B>";
    > ldap_close($ds) ;
    >
    > } else {
    > echo "<h4>Unable to connect to LDAP server</h4>";
    > }
    > //----------------------------------------------------------------
    >
    > Any suggestions welcome.
    > Mike[/color]

    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>

    Comment

    Working...