views:

199

answers:

1
<?php
    ini_set('display_errors',1);
    error_reporting(E_ALL);
    require_once('/include/adLDAP.php');
    $adldap = new adLDAP();

    $username = "user123";
    $password = "pass123";

    $authUser = $adldap->authenticate($username, $password);
    if ($authUser === true) {
      echo "<p>User authenticated successfully</p>";
    }
    else {
      echo "User authentication unsuccessful";
    }

    $result=$ldap->user_groups($username);
    print_r($result);

?>

I am using this class http://adldap.sourceforge.net/ and authentication works fine, but it gives me the following error:

Notice: Undefined variable: ldap in /web/protected/protected.php on line 18

Fatal error: Call to a member function user_groups() on a non-object in /web/protected/protected.php on line 18

Line 18 is:

$result=$ldap->user_groups($username);

Never used this class before, so I am unsure of why it is giving me that error, any help is appreciated.

+2  A: 

When instanciating the adLDAP class, you're storing the instance object in $adldap :

$adldap = new adLDAP();


But, later, you are trying to use $ldap :

$result=$ldap->user_groups($username);

That $ldap variable doesn't exist -- hence the notice.


And as it doesn't exist, PHP considers it's null

And null is not an object -- which means you cannot call a method on it -- which explains the Fatal Error.


I suppose you should replace this line :

$result=$ldap->user_groups($username);

By this one :

$result=$adldap->user_groups($username);

Note the $adldap instead of $ldap, to use the instance of your adLDAP class, instead of a non-existing variable.

Pascal MARTIN