<?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.
When instanciating the
adLDAPclass, you’re storing the instance object in$adldap:But, later, you are trying to use
$ldap:That
$ldapvariable doesn’t exist — hence the notice.And as it doesn’t exist, PHP considers it’s
nullAnd
nullis not an object — which means you cannot call a method on it — which explains the Fatal Error.I suppose you should replace this line :
By this one :
Note the
$adldapinstead of$ldap, to use the instance of youradLDAPclass, instead of a non-existing variable.