...

View Full Version : Undefined offset



Silverflames
10-09-2009, 02:21 PM
Im having problems with a script. When it is run I get the following error

PHP Notice: Undefined offset: 0 in xxx on line 103

Here is the code



/* LDAP Code begin */
+ $ldap = array('ldaphost' => 'ldap.admod.com',
+ 'ldaprdn' => 'cn=authcheck,ou=System,ou=Accounts,dc=admod,dc=com',
+ 'ldappass' => 'xxxxxxxxx',
+ 'dn' => 'ou=People,ou=Accounts,dc=admod,dc=com');
+ $info = array();
+ $ldapconn = ldap_connect($ldap['ldaphost']);
+ ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
+ $ldapbind = ldap_bind($ldapconn, $ldap['ldaprdn'], $ldap['ldappass']);
+ $username = $form['username'];
+ $password = $form['password'];
+ $filter = "(&(uid=$username) (accountStatus=active))";
+ $sr = ldap_search($ldapconn, $ldap['dn'], $filter);
+ $info = ldap_get_entries($ldapconn, $sr);
+ if (!empty($info)) {
+ $sr = ldap_compare($ldapconn, $info[0]["dn"], "userPassword", '{MD5}' . base64_encode(pack('H*', md5($password))));
+ }


I've not written this code myself, and Im not sure what is wrong. The line this error is referring to is here

$sr = ldap_compare($ldapconn, $info[0]["dn"],


Anyone have any clues?

Fumigator
10-09-2009, 04:05 PM
Well your $info array doesn't contain a value for the "0" index. Your check if (!empty($info)) { isn't doing the job; you really need to be checking for that "0" index instead using isset().



if (isset($info[0])) {



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum