简体   繁体   中英

Updating user fields in Active Directory with ldap_mod_replace

I am trying to update the mobile field for a user in Active Directory but I keep getting the following error. I have been trying to solve this for hours. It's probably something simple.

Warning: ldap_mod_replace(): Modify: Invalid syntax in /var/www/php_builders/admin/user_update/user_update_action.php on line 183

When I output the array, the mobile number shows up. its not empty.

ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
$adconn = ldap_connect("ldap://earth.example.com") or die("Couldn't connect to AD!");
$set = ldap_set_option($adconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_get_option($adconn, LDAP_OPT_PROTOCOL_VERSION, $value); 
$DN = 'CN=itcoopadmin,CN=Users,DC=example,DC=com';
$ldap_bind = ldap_bind($adconn, $DN, "**********");
$dn = trim($_POST['dn']);
$mobile = trim($_POST['mobile']);

if(!empty($mobile)) {
    $AD_mobile = AD_format($mobile);
    $DB_mobile = DB_format($mobile);
    $attributes['mobile'] = $AD_mobile;
} else {
    $DELETEattrs["mobile"] = array();
    $DELETEattrs = array();
}


$replace=ldap_mod_replace($adconn, $dn, $attributes); // Line 183, where the error is getting triggered

$disconnect = ldap_unbind($adconn);

AFAIK the attribute has to be given as array. So I'd suggest that you try this:

$attributes['mobile'] = array($AD_mobile);

Hope that helps

如果仍然有人在寻找,请尝试:

$attributes['mobile'][0] = $AD_mobile;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM