开发者

ldap_add: Invalid syntax

开发者 https://www.devze.com 2023-01-09 23:36 出处:网络
I\'m trying to add an Active Directory record via PHP. The CN contains a apostrophe (single quote), and I\'m trying to find the correct way to escape it.

I'm trying to add an Active Directory record via PHP. The CN contains a apostrophe (single quote), and I'm trying to find the correct way to escape it.

Things I've tried:

$dn = "CN=Conan O'Brien,OU=test,DC=test";
ldap_add($link_id, $dn, $attributes);
ldap_add($link_id, addslashes($dn), $attributes);
ldap_add($l开发者_如何学运维ink_id, str_replace("'", "\\39", $dn), $attributes);

Each one gives the same error. Obviously, I have verified this code works without an apostrophe in the DN.

ldap_add(): Add: Invalid syntax


You need to use two apostrophes instead of one. It's because one escapes the other.

The \ escaping is used for special characters ("," ";" "=" etc...) and hexadecimal-encoded characters, which is used when the value has no string representation.

0

精彩评论

暂无评论...
验证码 换一张
取 消