1,105,332 Community Members

php ldap_search operation error

Member Avatar
code739
Posting Whiz in Training
213 posts since May 2012
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 6 [?]
 
0
 

help me find out what's wrong with this code i got stuck with this error

ldap_search Search: Operations error

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$ADServer = 'sample.example.net';
$loginto = 'Aboitiz';
$uname = $_POST['uname'];
$passwd = $_POST['pass'];


$ldapconn = ldap_connect($ADServer) or die("Could not connect to LDAP server.");
$ldaprdn = $loginto."\\".$uname; 
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $passwd); 

if($ldapbind){
     $find = array("cn", "givenname", "samaccountname", "homedirectory", "telephonenumber", "mail");

    $base = "DC=example,DC=net";
    $email = "toytoy.me@example.net";
    $filter = "mail=".$email;

    $result = ldap_search($ldapconn,$base,$filter,$find);
    if(!$result){

        die('Error - '.ldap_error($ldapconn));
    }

    $info = ldap_get_entries($ldapconn, $result);
    print_r($info);
}else{
    echo 'user dont exists';
}
ldap_close($ldapconn);
?>
LastMitch
Deleted Member
 
0
 

@code739

php ldap_search operation error

This is the line that has the error:

$result = ldap_search($ldapconn,$base,$filter,$find);

You trying to search in Active Directory?

If you look closely it's this code:

$ldapconn = ldap_connect($ADServer) or die("Could not connect to LDAP server.");

The error means you are not connect correctly.

There should be a bridge connecting to $ldapconn and to $ldapbind.

Once it is connected your issue should be resolve.

I think.

Let me know if you have more questions.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: