1.11M Members

php ldap_search operation error

 
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.

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

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