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);
?>
Member Avatar for LastMitch

@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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.