Couse there was no example code for this function, i had alot of troubles to make it work properly.
So, here is working example:
function rebind_on_ref ($ds, $ldap_url) {
global $binddn; // DN used to bind
global $bindpw; // password used to bind
// required by most modern LDAP servers, use LDAPv3
ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, 3);
if (!ldap_bind($a,$binddn,$bindpw)) {
print "Cannot bind";
}
}