Showing paste #bioG:

<?php
			
function ldapserviceping($host, $port=389, $timeout=2) {
    $op = fsockopen($host, $port, $errno, $errstr, $timeout);
    if (!$op) return 0; //DC is N/A
    else {
        fclose($op); //explicitly close open socket connection
        return 1; //DC is up & running, we can safely connect with ldap_connect
    }
}
			
$dclist = array('nt-dc-one.xxxxxxxx.local', 'nt-dc-two.xxxxxxxx.local');
foreach ($dclist as $k => $dc) 
	if (ldapserviceping($dc) == true) break; else $dc = 0;
include('ldap.php');
$myldap = new Ldap;		
$myldap->setconfig('xxxxxxxx\\user', 'pass', "dc=xxxxxxxx,dc=local", $dc, true);
if (!$myldap->bind() || !$dc){
	//if ($dc) $GLOBALS['PHP_AUTH_ERROR'] = $myldap->get_error();
	//else $GLOBALS['PHP_AUTH_ERROR'] = "NO DOMAIN CONTROLLERS AVAILABLE AT PRESENT, PLEASE TRY AGAIN LATER!";
	//auth_fails();
} else {
	//auth_ok();
	//...
}

?>
Make a new paste